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> Quote Link to comment 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. Quote Link to comment 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.. Quote Link to comment 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? Quote Link to comment 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.