wkilc Posted July 22, 2008 Share Posted July 22, 2008 $page_name is grabbing the complete, current URL, including any active queries... When I attempt to filter that active page using a pull-down menu: <form name="form" action="<? echo "$page_name" ?>" method="get"> <? $result = @mysql_query("select distinct school from mytable ORDER BY school ASC"); if (mysql_num_rows($result) > 0) { print "<select name=\"school\">"; ?> <? while ($row = mysql_fetch_array($result)) { print "<option "; if($_GET['school'] == $row['school'] ){ echo "selected=\"selected\""; } print " value=\"" . $row['school'] . "\">" . $row['school'] . "</option>\n"; } print "</select>"; } mysql_free_result($result); ?> <input type="submit" value="Go"> </form> When I view the source on my page, it looks like this: <form name="form" action="/index.php?limit=50" method="get"> <select name="school"> <option value="school1" value="">school1</option> <option value="school2">school2</option> <option value="school3">school3</option> </select> <input type="submit" value="Go"> </form> ... notice the ?limit=50, which was captured, as that's how the page was currently sorted... But, when I click the submit button, I get: index.php?school=school1 When what I really want is: index.php?limit=50&school=school1 I CAN make it work with a link: <a href='<? echo "$page_name" ?>&school=school1'>School 1</a> ...but not my dynamic menu. Anyone point me in the right direction? Thanks. ~Wayne Link to comment https://forums.phpfreaks.com/topic/115944-pull-down-menu-query/ Share on other sites More sharing options...
mg.83 Posted July 22, 2008 Share Posted July 22, 2008 Hi Wayne, The way I see it is you have 2 options. 1. write a javascript function that builds the url (ie. /index.php?limit=50&school=school1) this can be done by altering this <input type="submit" value="Go"> to something like this <input type="button" value="Go" onClick="buildURL();"> and this print "<select name=\"school\">"; ?> to print "<select name=\"school\" id=\"school\">"; ?> then you would need a function such as function buildURL() { var school = document.getElementById('school').value; var url = '<?php echo $page_name; ?>&school='+school; window.location=url; } OR option 2 alter this: print " value=\"" . $row['school'] . "\">" . $row['school'] . "</option>\n"; to become print "value=\"".$page_name ."&school=". $row['school'] . "\">" . $row['school'] . "</option>\n"; hope that helps you some. Link to comment https://forums.phpfreaks.com/topic/115944-pull-down-menu-query/#findComment-596145 Share on other sites More sharing options...
wkilc Posted July 22, 2008 Author Share Posted July 22, 2008 Thank you. I'm hoping to avoid JS, if possible... but I'll keep it in mind. I had tried something similar to: print "value=\"".$page_name ."&school=". $row['school'] . "\">" . $row['school'] . "</option>\n"; When I tried it again, the resulting URL after I hit submit was crazy: index.php?school=%2Findex.php%3Flimit%3D50%26school%3Dschool1 Thanks. ~Wayne Link to comment https://forums.phpfreaks.com/topic/115944-pull-down-menu-query/#findComment-596154 Share on other sites More sharing options...
wkilc Posted July 22, 2008 Author Share Posted July 22, 2008 Since I could make it go with links... I ended up making the pull-down menu nothing more than a list of links... works great, but relies on JavaScript. <form name="Form"> <? $result = @mysql_query("select distinct school from mytable ORDER BY school ASC"); if (mysql_num_rows($result) > 0) { print "<select name=\"link\">"; while ($row = mysql_fetch_array($result)) { print "<option "; if($_GET['school'] == $row['school'] ){ echo "selected=\"selected\""; } print " value=\"$page_name&school=" . $row['school'] . "\">" . $row['school'] . "</option>\n"; } print "</select>"; } ?> <input type="button" value="Go" onclick="openURL()"> </form> This code build my links just fine... I'm gonna work with this.. but if anyone knows how to fix my original code, I'd be very appreciative. Thanks again. ~Wayne Link to comment https://forums.phpfreaks.com/topic/115944-pull-down-menu-query/#findComment-596164 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.