grantf Posted March 19, 2008 Share Posted March 19, 2008 Hi, i have a drop box in a form that is populated using a SQL query. It works well however i would like to have it so that when the page is initially loaded the drop box is blank, and not have the first entry pre-loaded. I havent been able to do this using the HTML/PHP code so my current (messy) work around is having a blank SQL record and it makes it seem as though the first record is empty.. how to write this line to accomplish this and do away with the dodgy SQL record?? <?php $link = mysql_connect( $myServer, $myUser, $myPass ); mysql_select_db( $myDB, $link ); $init=mysql_init("STOREDPROCEDURE", $link); $result = mysql_exec($init); ?> <select name="VALUE" id="VALUE"> <?php while ($row = mysql_fetch_object($result)) { echo "<option value='" . $row->name . "'>" . $row->name . "</option>"; } ?> </select> Link to comment https://forums.phpfreaks.com/topic/96888-drop-box-sql-populate-initially-blank/ Share on other sites More sharing options...
defeated Posted March 19, 2008 Share Posted March 19, 2008 In your html put: <option selected value=""></option> Then add in the rest of your php. Link to comment https://forums.phpfreaks.com/topic/96888-drop-box-sql-populate-initially-blank/#findComment-495795 Share on other sites More sharing options...
grantf Posted March 20, 2008 Author Share Posted March 20, 2008 thanks defeated but all that does it select the last entry in the dropbox.. Link to comment https://forums.phpfreaks.com/topic/96888-drop-box-sql-populate-initially-blank/#findComment-496586 Share on other sites More sharing options...
defeated Posted March 20, 2008 Share Posted March 20, 2008 <?php $link = mysql_connect( $myServer, $myUser, $myPass ); mysql_select_db( $myDB, $link ); $init=mysql_init("STOREDPROCEDURE", $link); $result = mysql_exec($init); ?> <select name="SELECT" id="SELECT"> <option selected value='anything you like'></option> <?php while ($row = mysql_fetch_object($result)) { echo "<option value='" . $row->name . "'>" . $row->name . "</option>"; } ?> </select> How about that? Link to comment https://forums.phpfreaks.com/topic/96888-drop-box-sql-populate-initially-blank/#findComment-496639 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.