segyn Posted May 31, 2007 Share Posted May 31, 2007 My drop down menu works fine but what I want is one of the options in the database for Status is Good. I want that to be the default option. If i enter selected in the option value such as selected="good" it just defaults to putting obsolete as the default value. Any Ideas on how to get this to work will be greatly appreciated. I am currently running php ver. 4.2.3 The site i'm working on is just to keep track of all the tools we have at the company I work for. So i have a lot of drop down boxes i made like this so i could just include them into each page. <?php echo"<tr bgcolor='Black'> <td bgcolor='silver'> Status: <td bgcolor='silver'>"; include("conn.php"); $sql = mysql_query("SELECT * FROM Tools.Status"); echo "<select name ='Status'>"; while($row = mysql_fetch_array($sql)) { echo "<option>" . $row['G_Status'] ."</option>"; } echo "</select>"; echo "</tr>"; mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/53728-solved-help-with-drop-down-box/ Share on other sites More sharing options...
MadTechie Posted May 31, 2007 Share Posted May 31, 2007 i'm not sure how you know when something is going to be the default so i guessed its when $row['G_Status'] == "Good", so change that if needed i think this is what you want! $default = ($row['G_Status'] == "good")?" selected ":""; echo "<option $default>{$row['G_Status']}</option>"; EDIT: replacing the echo "<option>" . $row['G_Status'] ."</option>"; line Quote Link to comment https://forums.phpfreaks.com/topic/53728-solved-help-with-drop-down-box/#findComment-265516 Share on other sites More sharing options...
chrisprse Posted May 31, 2007 Share Posted May 31, 2007 Try changing this: while($row = mysql_fetch_array($sql)) { echo "<option>" . $row['G_Status'] ."</option>"; } To: while($row = mysql_fetch_array($sql)) { if($row['G_Status'] == "good") { echo "<option value="" selected>" . $row['G_Status'] ."</option>"; } else { echo "<option value="">" . $row['G_Status'] ."</option>"; } } Chris Quote Link to comment https://forums.phpfreaks.com/topic/53728-solved-help-with-drop-down-box/#findComment-265519 Share on other sites More sharing options...
segyn Posted May 31, 2007 Author Share Posted May 31, 2007 Thanks this made it work. Try changing this: while($row = mysql_fetch_array($sql)) { echo "<option>" . $row['G_Status'] ."</option>"; } To: while($row = mysql_fetch_array($sql)) { if($row['G_Status'] == "good") { echo "<option value="" selected>" . $row['G_Status'] ."</option>"; } else { echo "<option value="">" . $row['G_Status'] ."</option>"; } } Chris Quote Link to comment https://forums.phpfreaks.com/topic/53728-solved-help-with-drop-down-box/#findComment-265535 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.