Shrekken Posted June 10, 2005 Share Posted June 10, 2005 Ok, I can get the search to work, displaying members info when the selections are made in the drop-downs but I can't seem to figure out how to get the search to select all options if Any is selected. For example: A drop-down with 3 options- Any, Male, Female. Selecting Male or Female works fine, but can't seem to figure out the right code to get both Male and Female when Any is selected. I understand that I need to create the code that says to get Male and Female when any is selected but everything I've tried so far hasn't worked and I've spent the last two days trying. I got a number of fields I need to apply this to. Hopefully someone knows what I'm talking about here, and I'd really appreciate some help. If you need to see the code, please ask. Shrekken Quote Link to comment https://forums.phpfreaks.com/topic/2353-search-problem-with-drop-down-lists/ Share on other sites More sharing options...
virtual_odin Posted June 10, 2005 Share Posted June 10, 2005 Sounds like you need to break the test into two 'if's if 'any' is selected then have no 'where' criteria related to gender if 'M' or 'F' is selected have the approprate 'where' in the query Set up the first part of the query with something like $query = "select * from xxx "; and then in the logical bit have $query .= "where gender = '".$var."'"; to create the condition. Note the space at the end of the first $query = bit otherwise your where will be concatenated and fail. Quote Link to comment https://forums.phpfreaks.com/topic/2353-search-problem-with-drop-down-lists/#findComment-7727 Share on other sites More sharing options...
Shrekken Posted June 10, 2005 Author Share Posted June 10, 2005 Sounds like you need to break the test into two 'if's if 'any' is selected then have no 'where' criteria related to gender if 'M' or 'F' is selected have the approprate 'where' in the query Set up the first part of the query with something like $query = "select * from xxx "; and then in the logical bit have $query .= "where gender = '".$var."'"; to create the condition. Note the space at the end of the first $query = bit otherwise your where will be concatenated and fail. 241254[/snapback] Well I tried that and variants of it but no luck. I really need Any to equal both Male and Female. Everything I've tried just returns 0 matches. I'm at my wits end with this stupid search thing and I'm now totally confused by it. Here's what one part looks like: [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--] $lookfor1_rsSearchads = \"1\"; if (isset($lookfor)) { $lookfor1_rsSearchads = (get_magic_quotes_gpc()) ? $lookfor : addslashes($lookfor); } mysql_select_db($database_mysql, $mysql); $query_rsSearchads = sprintf(\"SELECT users.`user`, userads.sex, users.age, userads.country, userads.county, userads.forwhat, userads.iam, userads.iam2, userads.hkids, userads.wkids, userads.iam3, userads.lookfor FROM userads, users WHERE userads.`user` = users.`user` AND users.age BETWEEN \'%s\' AND \'%s\' AND users.sex = \'%s\' ORDER BY age, users.age\", $colname1_rsSearchads,$colname2_rsSearchads,$lookfor1_rsSearchads); $query_limit_rsSearchads = sprintf(\"%s LIMIT %d, %d\", $query_rsSearchads, $startRow_rsSearchads, $maxRows_rsSearchads); $rsSearchads = mysql_query($query_limit_rsSearchads, $mysql) or die(mysql_error()); $row_rsSearchads = mysql_fetch_assoc($rsSearchads);[/span][!--PHP-Foot--][/div][!--PHP-EFoot--] This part is another way I tried but got stuck with: [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--][span style=\"color:#0000BB\"]<?php [/span][span style=\"color:#007700\"]if ([/span][span style=\"color:#0000BB\"]$HTTP_POST_VARS[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'lookfor\'[/span][span style=\"color:#007700\"]] == [/span][span style=\"color:#DD0000\"]\"Any\"[/span][span style=\"color:#007700\"]) { [/span][span style=\"color:#0000BB\"]$lookfor [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#FF8000\"]//Tried everything I can think of but I get 0 matches [/span][span style=\"color:#007700\"]} elseif ([/span][span style=\"color:#0000BB\"]$HTTP_POST_VARS[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'lookfor\'[/span][span style=\"color:#007700\"]] == [/span][span style=\"color:#DD0000\"]\"Male\"[/span][span style=\"color:#007700\"]) { [/span][span style=\"color:#0000BB\"]$lookfor [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"Male\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#FF8000\"]// This works fine [/span][span style=\"color:#007700\"]} elseif ([/span][span style=\"color:#0000BB\"]$HTTP_POST_VARS[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'lookfor\'[/span][span style=\"color:#007700\"]] == [/span][span style=\"color:#DD0000\"]\"Female\"[/span][span style=\"color:#007700\"]) { [/span][span style=\"color:#0000BB\"]$lookfor [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"Female\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#FF8000\"]// This works fine [/span][span style=\"color:#007700\"]} [/span][span style=\"color:#0000BB\"]?>[/span] [/span][!--PHP-Foot--][/div][!--PHP-EFoot--] I'm just trying to find the way to go with this first one then I'll be able to apply the same for all the other fields. Just so you know, the form itself is on a different page. I would buy a better book on php but I don't have the cash at the moment, so sorry to keep picking your brains. I only started learning php about 3 weeks ago. Quote Link to comment https://forums.phpfreaks.com/topic/2353-search-problem-with-drop-down-lists/#findComment-7728 Share on other sites More sharing options...
Shrekken Posted June 13, 2005 Author Share Posted June 13, 2005 Just thought I'd let you all know, I found the solution to the problem completely when I wasn't expecting it. The funny thing is, it actually made me jump 'cos I was so shocked! LMAO! All that at 3am as well! Anyway, the problem was what I had that shouldn't have been there. [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--][span style=\"color:#0000BB\"]<?php [/span][span style=\"color:#007700\"]if ([/span][span style=\"color:#0000BB\"]$HTTP_POST_VARS[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'lookfor\'[/span][span style=\"color:#007700\"]] == [/span][span style=\"color:#DD0000\"]\"Female\"[/span][span style=\"color:#007700\"]) { [/span][span style=\"color:#0000BB\"]$lookfor [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"Female\"[/span][span style=\"color:#007700\"]; } elseif ([/span][span style=\"color:#0000BB\"]$HTTP_POST_VARS[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'lookfor\'[/span][span style=\"color:#007700\"]] == [/span][span style=\"color:#DD0000\"]\"Male\"[/span][span style=\"color:#007700\"]) { [/span][span style=\"color:#0000BB\"]$lookfor [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"Male\"[/span][span style=\"color:#007700\"]; } else { [/span][span style=\"color:#0000BB\"]$lookfor [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"\'*\'\"[/span][span style=\"color:#007700\"]; } [/span][span style=\"color:#0000BB\"]?>[/span] [/span][!--PHP-Foot--][/div][!--PHP-EFoot--] The above is the correct code. All I did was to remove [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--] ($HTTP_POST_VARS[\'lookfor\'] == \"Any\") [/span][!--PHP-Foot--][/div][!--PHP-EFoot--] from the else. So I hope this goes some way to helping someone else. Especially if it's going to save you 4 days of frustration and sleepless nights! Quote Link to comment https://forums.phpfreaks.com/topic/2353-search-problem-with-drop-down-lists/#findComment-7731 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.