Drop Down Menu

Discussion in 'PHP' started by utahfriend, Nov 11, 2005.

  1. #1
    I have created a drop down menu pulling items from Mysql. When I choose an item and save it, it saves it ok. When I reopen the item, the drop down menu shows the default item "Select" instead of the item that was saved. If I save the item without changing the selection in the drop down menu, it saves "Select" to the table.

    How do I make the drop down menu show the item that was saved when it opens up. (So it saves the previously saved version) You can see the results of this page at: http://store.globalmarketingplus.com/UserFiles/118/editmembers.php?detailsId=12

    Here is my code:

    function dd_template($cat_id=0) 
    { 
    
    $text = "<option value='Select'>Select</option>"; 
    $user_id = '118'; 
    $sql = "SELECT cat_id, cat_name FROM members_cat where `user_id` = '".$user_id."' order by cat_name"; 
    $result = mysql_query($sql); 
    while($row = mysql_fetch_array($result)) 
    { 
    $text .= "<option value='$row[cat_name]'"; 
    if ($row["cat_id"] == $cat_id) 
    { 
    $text .= " Selected"; 
    } 
    $text .= "> $row[cat_name]</option>\n"; 
    } 
    $text .= "</select>"; 
    return $text; 
    } 
    PHP:
     
    utahfriend, Nov 11, 2005 IP
  2. palespyder

    palespyder Psycho Ninja

    Messages:
    1,254
    Likes Received:
    98
    Best Answers:
    0
    Trophy Points:
    168
    #2
    You got this working then I assume?
     
    palespyder, Nov 12, 2005 IP