Jump to content

Search multiple fields without having exact matches


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

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.