rsammy Posted November 10, 2006 Share Posted November 10, 2006 I have some fields on my screen which are drop-down boxes. right now, i either have them default to the very first on the list or a selected value. i need to do it slightly different. i need to insert a blank value in the drop down and make it the default and then display the list from the database. heres my code ... <tr> <td width="275"> <div align="right"><font class="inputLbl">Preferred Provider: </font></div></td> <td colspan="2"> <?PHP $query="select phy_id, phy_fname, phy_lname from phy_det where phy_disabled = 'Enable' order by phy_lname, phy_fname"; $result= mysql_query ($query); if ($result) { print ("<select name='physician'>"); if ($row = mysql_fetch_array($result)) { do { print("<option value=\""); print $row["phy_id"]; if($pat_phy_id == $row["phy_id"]) { print("\" selected>"); } else { print("\">"); } print $row["phy_lname"]; print (", "); print $row["phy_fname"]; print("</option>"); } while($row = mysql_fetch_array($result)); } } print ("</select>"); ?> </td></tr>now, how do i insert a blank in the drop down before filling it with values obtained from the query? help please... thanx in advance! Link to comment https://forums.phpfreaks.com/topic/26843-inserting-blank-value-in-a-drop-down/ Share on other sites More sharing options...
haaglin Posted November 10, 2006 Share Posted November 10, 2006 If i understand you right, then this is what you want:[code]<?php$query="select phy_id, phy_fname, phy_lname from phy_det where phy_disabled = 'Enable' order by phy_lname, phy_fname";$result = mysql_query ($query); if ($result) { echo "<select name='physician'>\n"; echo "<option value=\"\">Select one</option>\n"; while($row = mysql_fetch_array($result)) { if($pat_phy_id == $row["phy_id"]) { echo '<option selected value="'.$row["phy_id"].'">'.$row["phy_lname"].', '.$row["phy_fname"].'</option>'; } else { echo '<option value="'.$row["phy_id"].'">'.$row["phy_lname"].', '.$row["phy_fname"].'</option>'; } } echo "</select>";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/26843-inserting-blank-value-in-a-drop-down/#findComment-122735 Share on other sites More sharing options...
rsammy Posted November 10, 2006 Author Share Posted November 10, 2006 thank u sir! u made my day!! Link to comment https://forums.phpfreaks.com/topic/26843-inserting-blank-value-in-a-drop-down/#findComment-122745 Share on other sites More sharing options...
rsammy Posted November 10, 2006 Author Share Posted November 10, 2006 i really appreciate ur help haaglin!i need somemore help tho...now I am stuck with this one! this seems to be a pretty straight forward one, but I am not able to go ahead with this one either. I need to do the same here too... insert a blank in the drop down and default it to the blank on pageload.<tr> <td width="196"> <div align="right"><font class="inputLbl">Location: </font></div></td> <td colspan="2"> <?PHP $querys="SELECT org_ID, org_name FROM orgs where org_type !='Office' order by org_name ASC"; $results= mysql_query ($querys); if ($results) { print ("<select name='location'>"); if ($row= mysql_fetch_array($results)) { do { print ("<option value=\""); print $row["org_ID"]; print ("\">"); print $row["org_name"]; print ("</option>"); } while ($row = mysql_fetch_array($results)); } } print ("</select>"); ?> </td></tr>help please? Link to comment https://forums.phpfreaks.com/topic/26843-inserting-blank-value-in-a-drop-down/#findComment-122755 Share on other sites More sharing options...
haaglin Posted November 10, 2006 Share Posted November 10, 2006 Just use the previous code, and change the sql and $row values. Link to comment https://forums.phpfreaks.com/topic/26843-inserting-blank-value-in-a-drop-down/#findComment-122764 Share on other sites More sharing options...
rsammy Posted November 10, 2006 Author Share Posted November 10, 2006 i am confused at the point where u r comparing the phy_id to pat_phy_id. i dont have an id to compare withhere. i just need to display all results with a blank included. please help Link to comment https://forums.phpfreaks.com/topic/26843-inserting-blank-value-in-a-drop-down/#findComment-122778 Share on other sites More sharing options...
rsammy Posted November 10, 2006 Author Share Posted November 10, 2006 never mind, i figured it out. uve been a great help. thanx Link to comment https://forums.phpfreaks.com/topic/26843-inserting-blank-value-in-a-drop-down/#findComment-122784 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.