mishasoni Posted October 10, 2008 Share Posted October 10, 2008 Hi - Could someone enlighten me as to how to mass multiple url variables using an OR operator? For example, I want to return results where $var1=X OR $var1=Y, but am not sure what the url string should look like. www.mydomain.com/page.php?var1=... Any help would be greatly appreciated! Link to comment https://forums.phpfreaks.com/topic/127879-pass-multiple-url-variables-using-or-operator/ Share on other sites More sharing options...
Maq Posted October 10, 2008 Share Posted October 10, 2008 I don't understand this OR condition has to be done before you add it into the URL string. Do you have any code so far? Link to comment https://forums.phpfreaks.com/topic/127879-pass-multiple-url-variables-using-or-operator/#findComment-662087 Share on other sites More sharing options...
Stryves Posted October 10, 2008 Share Posted October 10, 2008 $var1=1 if($var1==1 || $var==2) { // echo the url, www.mydomain.com/page.php?var1=$var1 } Like this? Link to comment https://forums.phpfreaks.com/topic/127879-pass-multiple-url-variables-using-or-operator/#findComment-662099 Share on other sites More sharing options...
mishasoni Posted October 14, 2008 Author Share Posted October 14, 2008 I will clarify what I am trying to do... I'm trying to create a drop down menu that returns only records where the 'NameLast' field begins with a given letter, A, B ,C ...etc, so that users can browse by last name. I would like to group UVW and XYZ together in the menu options since there are very few records beginning with these letter, but am unsure how to go about doing this (I should disclose that I am a PHP newbie). See code for the menu below. //Contents for menu var menu1=new Array() menu1[0]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=A">A</a>' menu1[1]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=B">B</a>' menu1[2]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=C">C</a>' menu1[3]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=D">D</a>' menu1[4]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=E">E</a>' menu1[5]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=F">F</a>' menu1[6]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=G">G</a>' menu1[7]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=H">H</a>' menu1[8]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=I">I</a>' menu1[9]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=J">J</a>' menu1[10]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=K">K</a>' menu1[11]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=L">L</a>' menu1[12]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=M">M</a>' menu1[13]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=N">N</a>' menu1[14]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=O">O</a>' menu1[15]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=P">P</a>' menu1[16]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=Q">Q</a>' menu1[17]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=R">R</a>' menu1[18]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=S">S</a>' menu1[19]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=T">T</a>' menu1[20]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?.....</a>' // should return all records beginning with U, V or W menu1[21]='<a href="http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?.....</a>' // should return all records beginning with X, Y, or Z Link to comment https://forums.phpfreaks.com/topic/127879-pass-multiple-url-variables-using-or-operator/#findComment-665341 Share on other sites More sharing options...
wildteen88 Posted October 14, 2008 Share Posted October 14, 2008 You'll use the following url instead http://www.agci.org/programs/scientist_workshops_%3E_past_participants/participant_results.php?firstletter=UVW Then in participant_results.php you'll check to see if $_GET['firstletter'] equals to UVW or XYZ if its does you'll grab all names that begin with U, V, W or X, Y, Z at the same time. Link to comment https://forums.phpfreaks.com/topic/127879-pass-multiple-url-variables-using-or-operator/#findComment-665379 Share on other sites More sharing options...
mishasoni Posted October 14, 2008 Author Share Posted October 14, 2008 OK, now I need a bit of handholding on the code for the results page. So far I have: $query_rsParticipants = "SELECT * FROM Contacts WHERE ContactType = 'Scientist' AND ContactID_pk <> 0 ORDER BY NameLast ASC"; $firstletter = $_GET['firstletter'] ; if (isset($firstletter) && $firstletter = UVW) { $query_rsParticipants = "SELECT * FROM Contacts WHERE ContactType = 'Scientist' AND ContactID_pk <> 0 AND NameLast LIKE 'U%' OR NameLast LIKE 'V%' OR NameLast LIKE 'W%' ORDER BY NameLast ASC"; } elseif (isset($firstletter) && $firstletter = XYZ) { $query_rsParticipants = "SELECT * FROM Contacts WHERE ContactType = 'Scientist' AND ContactID_pk <> 0 AND NameLast LIKE 'X%' OR NameLast LIKE 'Y%' OR NameLast LIKE 'Z%' ORDER BY NameLast ASC"; } else { $query_rsParticipants = "SELECT * FROM Contacts WHERE ContactType = 'Scientist' AND ContactID_pk <> 0 AND NameLast LIKE '$firstletter%' ORDER BY NameLast ASC"; } ...but this doesn't work – it returns results for UVW regardless of what $firstletter is set to. Any help? Is there a better way of accomplishing this? Thanks. Link to comment https://forums.phpfreaks.com/topic/127879-pass-multiple-url-variables-using-or-operator/#findComment-665540 Share on other sites More sharing options...
wildteen88 Posted October 14, 2008 Share Posted October 14, 2008 When comparing variables use == not = $search = null; if(isset($_GET['firstletter'])) { $firstletter = $_GET['firstletter']; if($firstletter == 'UVW') { $search = " AND NameLast LIKE 'U%' OR NameLast LIKE 'U%' OR NameLast LIKE 'V%' OR NameLast LIKE 'W%'"; } elseif($firstletter == 'XYZ') { $search = " AND NameLast LIKE 'U%' OR NameLast LIKE 'X%' OR NameLast LIKE 'Y%' OR NameLast LIKE 'Z%'"; } elseif(in_array(strtolower($firstletter), range('a','z'))) { $search = " AND NameLast LIKE '$firstletter%'"; } } $query_rsParticipants = "SELECT * FROM Contacts WHERE ContactType = 'Scientist' AND ContactID_pk <> 0". $search ." ORDER BY NameLast ASC"; Link to comment https://forums.phpfreaks.com/topic/127879-pass-multiple-url-variables-using-or-operator/#findComment-665551 Share on other sites More sharing options...
mishasoni Posted October 15, 2008 Author Share Posted October 15, 2008 Worked great. Thank you so much for all your help! Link to comment https://forums.phpfreaks.com/topic/127879-pass-multiple-url-variables-using-or-operator/#findComment-666208 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.