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
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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.