PHP_Idiot Posted July 10, 2009 Share Posted July 10, 2009 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"); Link to comment https://forums.phpfreaks.com/topic/165492-solved-have-list-box-stay-on-selected-item-on-page-reload/ Share on other sites More sharing options...
WolfRage Posted July 10, 2009 Share Posted July 10, 2009 This is actually an HTML question, but you need to assign selected="selected" to the appropriate option based on the user's selection. Link to comment https://forums.phpfreaks.com/topic/165492-solved-have-list-box-stay-on-selected-item-on-page-reload/#findComment-872826 Share on other sites More sharing options...
Jibberish Posted July 10, 2009 Share Posted July 10, 2009 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 ?> Link to comment https://forums.phpfreaks.com/topic/165492-solved-have-list-box-stay-on-selected-item-on-page-reload/#findComment-872828 Share on other sites More sharing options...
PHP_Idiot Posted July 10, 2009 Author Share Posted July 10, 2009 Jibberish you hero That's exactly what I wanted thanks a lot Link to comment https://forums.phpfreaks.com/topic/165492-solved-have-list-box-stay-on-selected-item-on-page-reload/#findComment-872832 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.