Jump to content

[SOLVED] Multiple Search


timmah1

Recommended Posts

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 ( :D)

 

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

Link to comment
https://forums.phpfreaks.com/topic/88136-solved-multiple-search/
Share on other sites

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!

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);

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.