Jump to content

Recommended Posts

What i have is a query that returns a list of values in a database for me to select using a drop down box.  In this case, I have dates in a database and I want each one of those dates to be provided to me as an option in a drop down.  This works perfectly.  What I am having trouble with is when I make a selection from the drop down and click "submit" I want the value that was submitted to be the default value in the drop down.  Currently, the first date shows up by default because I have "ORDER BY Date" in my query.  I want this to actually have the value that I submitted when clicking on "submit" to be the default value in the drop down instead of the earliest date.  So if I have $Date=$_POST['Date'];  with the Date value being "2008-05-09", I want that date to be the default value in the box. 

 

Let me know if this isn't clear and I will elaborate. Thank you in advance.

 

          <?php
                                                include("dbinfo.inc.php");
                                                mysql_connect("localhost",$username,$password);
                                                @mysql_select_db($database) or die( "Unable to select database");
                                                $query = "SELECT * FROM database ORDER BY Date";
                                                $result = mysql_query ($query);
                                                echo "<select name=Date>";
                                                                
                                                while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
                                                echo "<option value=$nt[Date]>$nt[Date]</option>";
                                                }
                                                echo "</select>";
                                                ?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.