wkilc Posted August 17, 2010 Share Posted August 17, 2010 Can someone help me code kind of a "advanced search" form, that will get a URL: <form method="get"> <input type="checkbox" name="level" value="PreK" /> <input type="checkbox" name="level" value="Elem" /> <input type="checkbox" name="level" value="MS" /> <input type="checkbox" name="level" value="HS" /> <input type="checkbox" name="subject" value="Math" /> <input type="checkbox" name="subject" value="Reading" /> <input type="checkbox" name="level" value="Science" /> <input type="submit" value="submit" /> </form> So... if I ticked PreK, Elem and Math, the resulting link would be: www.mysite.com?level=PreK&Elem&subject=Math The most complicated thing... how would I get place the "&" in between variables? Thank you once again. ~Wayne Quote Link to comment https://forums.phpfreaks.com/topic/211015-advanced-search-form/ Share on other sites More sharing options...
MadTechie Posted August 17, 2010 Share Posted August 17, 2010 No the URL would be ?level=PreK&level=Elem&level=MS which will overwrite each other! you need to use an array ie level[] eg <?php echo "<u>level</u><BR />"; if(!empty($_GET['level'])) foreach($_GET['level'] as $lev){ echo "$lev <BR />\n"; } echo "<u>subject</u><BR />"; if(!empty($_GET['subject'])) foreach($_GET['subject'] as $sub){ echo "$sub <BR />\n"; } ?> <form method="get"> <input type="checkbox" name="level[]" value="PreK" /> <input type="checkbox" name="level[]" value="Elem" /> <input type="checkbox" name="level[]" value="MS" /> <input type="checkbox" name="level[]" value="HS" /> <input type="checkbox" name="subject[]" value="Math" /> <input type="checkbox" name="subject[]" value="Reading" /> <input type="checkbox" name="level[]" value="Science" /> <input type="submit" value="submit" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/211015-advanced-search-form/#findComment-1100560 Share on other sites More sharing options...
wkilc Posted August 18, 2010 Author Share Posted August 18, 2010 Thank you! But now the URL contains [] ?level=PreK[]&level=Elem[]&level=MS[], ...which prevents the link from working. Is there a way to remove that but still allow it to echo the variables filtered? I'm very new to this... do I need to define the array here as well? Thanks again. ~Wayne Quote Link to comment https://forums.phpfreaks.com/topic/211015-advanced-search-form/#findComment-1100573 Share on other sites More sharing options...
MadTechie Posted August 18, 2010 Share Posted August 18, 2010 Works fine on IE and FF here Quote Link to comment https://forums.phpfreaks.com/topic/211015-advanced-search-form/#findComment-1100579 Share on other sites More sharing options...
wkilc Posted August 18, 2010 Author Share Posted August 18, 2010 My form tells me "No records found matching: Array" When I search: www.mysite.com?members.php?levels[]=Elem ... it thinks it's actually looking for a value called "Array". What am I missing? ~Wayne Quote Link to comment https://forums.phpfreaks.com/topic/211015-advanced-search-form/#findComment-1100581 Share on other sites More sharing options...
wkilc Posted August 18, 2010 Author Share Posted August 18, 2010 I've modified the query to include: and ((user_info.PreK LIKE '%$lev%') or (user_info.Elem LIKE '%$lev%')) and the form looks like thus: echo "<u>level</u><BR />"; if(!empty($_GET['lev'])) foreach($_GET['lev'] as $lev){ echo "$lev <BR />\n"; } echo "<u>subject</u><BR />"; if(!empty($_GET['sub'])) foreach($_GET['sub'] as $sub){ echo "$sub <BR />\n"; } ?> <form action="search_advanced.php" method="get"> <input type="checkbox" name="lev[]" value="PreK" />PreK <input type="checkbox" name="lev[]" value="Elem" />Elem <input type="checkbox" name="lev[]" value="MS" />MS <input type="checkbox" name="lev[]" value="HS" />HS <input type="checkbox" name="sub[]" value="Math" />Math <input type="checkbox" name="sub[]" value="Reading" />Reading <input type="submit" value="submit" /> </form> But... was you said, it's overwriting: advanced.php?lev[]=PreK&lev[]=Elem ...the above URL only gives me Elem, no PreK. ~Wayne Quote Link to comment https://forums.phpfreaks.com/topic/211015-advanced-search-form/#findComment-1100591 Share on other sites More sharing options...
MadTechie Posted August 18, 2010 Share Posted August 18, 2010 what does it display on the screen! Quote Link to comment https://forums.phpfreaks.com/topic/211015-advanced-search-form/#findComment-1100593 Share on other sites More sharing options...
wkilc Posted August 18, 2010 Author Share Posted August 18, 2010 Only members with lev=Elem Rather than members with either Elem or PreK... as I thought the query requested: advanced.php?lev[]=PreK&lev[]=Elem Thank you. ~Wayne Quote Link to comment https://forums.phpfreaks.com/topic/211015-advanced-search-form/#findComment-1100595 Share on other sites More sharing options...
MadTechie Posted August 18, 2010 Share Posted August 18, 2010 test here and it works as expected level PreK Elem subject via the URL and from the form Quote Link to comment https://forums.phpfreaks.com/topic/211015-advanced-search-form/#findComment-1100613 Share on other sites More sharing options...
wkilc Posted August 18, 2010 Author Share Posted August 18, 2010 Sorry... I had an error in my query. All sorted now. Thank you! ~Wayne Quote Link to comment https://forums.phpfreaks.com/topic/211015-advanced-search-form/#findComment-1100674 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.