timmah1 Posted January 28, 2008 Share Posted January 28, 2008 I'm trying to make a search for my database with multiple options (9 to be exact), I can't find anything anywhere on the internet to show how to do this. So I thought I'd try it myself ( ) Anyhow, I cannot get this to work These are the options they have $PostalCode $TownCity $EscortType $Duration $FullAddress $Bodytype $Age $Hair $Eyes This is the code for the search $PostalCode = $_POST['post']; $TownCity = $_POST['town']; $EscortType = $_POST['type']; $Duration = $_POST['dur']; $FullAddress = $_POST['place']; $Bodytype = $_POST['body']; $Age = $_POST['AgeRange']; $Hair = $_POST['HairC']; $Eyes = $_POST['EyesC']; $data = mysql_query("SELECT * FROM users WHERE PostalCode LIKE '%$post%' AND TownCity LIKE '%$town%' AND EscortType LIKE '%$type%', etc"); while($result = mysql_fetch_array( $data )) { echo $result['PostalCode']; echo " "; echo $result['TownCity']; } //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } } I keep getting an error. And yes, I know that 'etc' is in the query, that's not the problem. Can anybody help me out here or point me in the right direction for a tutorial on how to do this? Thank you in advance Quote Link to comment https://forums.phpfreaks.com/topic/88136-solved-multiple-search/ Share on other sites More sharing options...
vicodin Posted January 28, 2008 Share Posted January 28, 2008 What is the Error? Quote Link to comment https://forums.phpfreaks.com/topic/88136-solved-multiple-search/#findComment-450942 Share on other sites More sharing options...
me1000 Posted January 28, 2008 Share Posted January 28, 2008 the variables you are using in the query are not the post data variables. $data = mysql_query("SELECT * FROM users WHERE PostalCode LIKE '%$post%' it needs to be $PostalCode from the looks of it that needs to be done to all the variables, that is about all I can give you without knowing the error though! Quote Link to comment https://forums.phpfreaks.com/topic/88136-solved-multiple-search/#findComment-450946 Share on other sites More sharing options...
timmah1 Posted January 28, 2008 Author Share Posted January 28, 2008 Now it's saying "Sorry, but we can not find an entry to match your query" no matter what I put in the Postal Code field, even when I put exactly what is in the database. No more error Quote Link to comment https://forums.phpfreaks.com/topic/88136-solved-multiple-search/#findComment-450947 Share on other sites More sharing options...
timmah1 Posted January 28, 2008 Author Share Posted January 28, 2008 Here's the error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/honey/public_html/honey/test.php on line 32 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/honey/public_html/honey/test.php on line 40 Sorry, but we can not find an entry to match your query line 32 while($result = mysql_fetch_array( $data )) linke 40 $anymatches=mysql_num_rows($data); Quote Link to comment https://forums.phpfreaks.com/topic/88136-solved-multiple-search/#findComment-450949 Share on other sites More sharing options...
toplay Posted January 28, 2008 Share Posted January 28, 2008 You have an error in your query. Always verify a mysql command worked before executing subsequent (related) commands. Check and display any errors after $data = mysql_query() and before the fetch. Post for members the error you get from the query. Quote Link to comment https://forums.phpfreaks.com/topic/88136-solved-multiple-search/#findComment-450952 Share on other sites More sharing options...
timmah1 Posted January 28, 2008 Author Share Posted January 28, 2008 The code works like this $data = mysql_query("SELECT * FROM users WHERE PostalCode LIKE '%$PostalCode%' AND TownCity LIKE '%$TownCity%'") or die(mysql_error()); But as soon as I add another search variable $data = mysql_query("SELECT * FROM users WHERE PostalCode LIKE '%$PostalCode%' AND TownCity LIKE '%$TownCity%' AND EscortType LIKE '%$EscortType%'") or die(mysql_error()); it gives me the statement that it can't find what I'm looking for. Quote Link to comment https://forums.phpfreaks.com/topic/88136-solved-multiple-search/#findComment-450957 Share on other sites More sharing options...
toplay Posted January 28, 2008 Share Posted January 28, 2008 Well, maybe you meant to use "OR" instead of "AND". The use of "AND" means all must match the search criteria for it to return something (rows). Quote Link to comment https://forums.phpfreaks.com/topic/88136-solved-multiple-search/#findComment-450961 Share on other sites More sharing options...
timmah1 Posted January 28, 2008 Author Share Posted January 28, 2008 JESUS!!!! Something simple. Thank You <------------- moron Quote Link to comment https://forums.phpfreaks.com/topic/88136-solved-multiple-search/#findComment-450964 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.