Jump to content

Search multiple fields without having exact matches


TD

Recommended Posts

Hi, I have a little problem, but can't figure it out, how can i fix it?!?!? I would very appreciate any help.

 

DB:

Name:

Johny

Texas

Knight

 

Surname:

Walker

Ranger

Rider

 

I have only one search box and when i search one string like Johny or Walker everything works fine, but when i write them together, they just don't show up. My php code looks so:

 

if (empty($name)) {
$nam = "";
$nam2 = "";
}
else
{
$nam = "where (vards='$name' or uzvards='$name')";
$nam2 = "and vards='$name' or uzvards='$name')";
}

 

How should I write it correctly so that the script understands? Many thanks, hope You understand, what am i asking. :)

I will post the whole script:

 



if (empty($name)) {
$nam = "";
$nam2 = "";
}
else
{
$nam = "where (name='$name' or surname='$name')";
$nam2 = "and name='$name' or surname='$name')";
}



if (empty($region)) {
$regi = "$nam";
}
else
{
$regi = "where (regions='$region' $nam2)";
}

$sql = mysql_query("SELECT * FROM $tab $regi order by name, surname asc");

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.