Jump to content

[SOLVED] Have list box stay on selected item on page reload


PHP_Idiot

Recommended Posts

I have a list box that has four options in it.

When an option is selected and the 'Go' button is hit the table on the page populates with their information, but the list box reset to it show the first in the list again.

 

Is it possible to select option 3 and then when the page has refreshed have the listbox have option 3 as it's new default value?

 

this way the list box value reflects the contents of the newly populated table!

 

This code include the creation of the list box and the sql query that populates the table:

$query="SELECT VenueName FROM Venue ORDER BY VenueName";

$result = mysql_query ($query);
echo '<form action="" method="post">';
echo "<select name='Venue'>";
// printing the list box select command
while($nt=mysql_fetch_array($result))
        {//Array or records stored in $nt
                echo "<option value=\"$nt[VenueName]\">$nt[VenueName]</option>";
                /* Option values are added by looping through the array */
        }
echo "</select>";// Closing of list box 

?>
  <input type="submit" value="Go" />
  </form>
          </p>
          <h3><?php echo $_POST['Venue'] ?> League Positions</h3>
<?php 
if (isset($_POST['Venue']) && !empty($_POST['Venue'])) {
//mySQL queries

$query = "SELECT SUM(Position.Points) , Results.Date, Player.FirstName, Player.LastName, COUNT(Results.MembershipNo)
FROM Position, Player, Results, Venue
WHERE Player.MembershipNo = Results.MembershipNo
AND Date
BETWEEN '2009-07-05'
AND '2009-10-03'
AND Results.Position = Position.Position
AND Venue.VenueID = Results.VenueID
AND Venue.VenueName = '".$_POST['Venue']."'
GROUP BY Player.MembershipNo
ORDER BY SUM(Position.Points) DESC"; 
$result=mysql_query($query)
	or die ("couldn't execute query");

 

Something along these lines

 


<?php

echo '<form action="" method="post">';
echo "<select name='Venue'>";
// printing the list box select command
while($nt=mysql_fetch_array($result))
        {//Array or records stored in $nt
                echo "<option ";

                 if($_POST['Venue'] == $nt[VenueName]) echo "selected=\"selected\"";

               echo " value=\"$nt[VenueName]\">$nt[VenueName]</option>";
                /* Option values are added by looping through the array */
        }
echo "</select>";// Closing of list box 
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.