Grabbing the right record in a drop down from mysql
        Posted  
        
            by 86Stang
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by 86Stang
        
        
        
        Published on 2010-04-08T18:29:41Z
        Indexed on 
            2010/04/08
            18:33 UTC
        
        
        Read the original article
        Hit count: 144
        
I'm using a form where the user can edit an entry. Everything is populating and all is well with the exception that I can't get the drop down to show the project that they've already assigned the image to.
$project_qry = "SELECT * from projects ORDER BY title ASC";
$project_res = mysql_query($project_qry);
$project_drop = "<select name=\"project_id\">\n";
while ($row = mysql_fetch_array($project_res))
    {
    if ($project_id == $row[title])
        {
            $project_drop .= "<option value=\"$row[id]\" selected>$row[title]</option>\n";
        }
    else
        {
            $project_drop .= "<option value=\"$row[id]\">$row[title]</option>\n";
        }
}
$project_drop .= "</select>\n";
I'm sure it's something devilishly simple but I'm stumped.
© Stack Overflow or respective owner