wkilc Posted June 23, 2008 Share Posted June 23, 2008 index.php will show all records. I want to query (filter) the database like this: index.php?car=toyota or index.php?car=honda <form name="form" action="index.php" method="get"> <b>Filter cars:</b><br> <select name="car"> <option value="">DISPLAY ALL</option> <option value="honda">honda</option> <option value="toyota">toyota</option> <option value="ford">ford</option> </select> <input type="submit" value="Go"> </form> It works just fine... the page is filtered correctly. The only problem is with every submit, the menu defaults back to the first value "DISPLAY ALL". Is there any simple way to make the pulldown menu "hold" the value that it's currently displaying? Thanks, ~Wayne Link to comment https://forums.phpfreaks.com/topic/111430-solved-pulldown-menu-for-query/ Share on other sites More sharing options...
DarkWater Posted June 23, 2008 Share Posted June 23, 2008 Yeah, just echo selected="selected" on the one that you want selected. Link to comment https://forums.phpfreaks.com/topic/111430-solved-pulldown-menu-for-query/#findComment-571985 Share on other sites More sharing options...
maxudaskin Posted June 23, 2008 Share Posted June 23, 2008 <form name="form" action="index.php" method="get"> <b>Filter cars:</b><br> <select name="car"> <option <?php if(empty($_GET['car'])){ echo "selected=\"selected\""; } ?> value="">DISPLAY ALL</option> <option <?php if($_GET['car'] == "honda"){ echo "selected=\"selected\""; } ?> value="honda">honda</option> <option <?php if($_GET['car'] == "toyota"){ echo "selected=\"selected\""; } ?> value="toyota">toyota</option> <option <?php if($_GET['car'] == "ford"){ echo "selected=\"selected\""; } ?> value="ford">ford</option> </select> <input type="submit" value="Go"> </form> OR <form name="form" action="index.php" method="get"> <b>Filter cars:</b><br> <select name="car"> <option value="">DISPLAY ALL</option> <?php $values = array("Honda","Toyota","Ford"); $num_vals = count($values); for($i = 1,$i <= $num_vals, $i++){ if($values[$i] == $_GET['car']){ echo "<option selected=\"selected\" value=\"$value[$i]\">$value[$i]</option>"; }else{ echo "<option value=\"$value[$i]\">$value[$i]</option>"; } } ?> </select> <input type="submit" value="Go"> </form> Link to comment https://forums.phpfreaks.com/topic/111430-solved-pulldown-menu-for-query/#findComment-571986 Share on other sites More sharing options...
wkilc Posted June 23, 2008 Author Share Posted June 23, 2008 Thanks so much! ~Wayne Link to comment https://forums.phpfreaks.com/topic/111430-solved-pulldown-menu-for-query/#findComment-572013 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.