SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Taunton, UK
    Posts
    787
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Retrieving value of drop down selection

    Hi there

    I have a dynamically generated drop down box on one page and I want grab the selected value as well as the selected option on another page

    Here is my code that creates the drop down

    Code:
    <select name="select_musician">
    						
    
    <?php
    
    while ($musician = mysql_fetch_array($musicians)) {
    
    $musicianid = $musician['id'];
    $musicianname = htmlspecialchars($musician['name']);
    echo "<option value='$musicianid'>$musicianname</option>\n";
    
    }
    							
    ?>
    
    </select>
    And on the page where I want to get the data, I have the following which gets me the option chosen

    Code:
    $musicianid = $_POST['select_musician'];
    Is it possible to get the musicianid too?

    I tried the following but it doesn't work

    Code:
    $musicianname = $_POST['select_musician.value'];
    Thanks in advance

    Paul

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    No, that's JavaScript syntax.

    To get the name, you have to requery the database to fetch it:
    PHP Code:
    $musicianid $_POST['select_musician'];
    $q mysql_query("SELECT `name` FROM `musicians` WHERE `id` = '".$musician."'");
    $musicianname mysql_result($q0); 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Taunton, UK
    Posts
    787
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks arkinstall - I just wanted to check there wasn't a way to avoid calling to queries to the database. That is fine though as it appears to work and the site is not going to have a lot of traffic.

    Many thanks

    Paul


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •