user796834
user796834

Reputation: 11

Make PHP to search everything

I was wondering how I would search more tables in my search database to include city and search. City and search is already in my database all I need to do is search them, but i don't know how.

This is what i have so far:

//explode out search term
$search_exploded = explode(" ",$search);

foreach($search_exploded as $search_each) {

//construct query
$x++;
if ($x==1)
    $construct .= " keywords LIKE '%$search_each%'";
else
    $construct .= " OR keywords LIKE '%$search_each%'";
}

Upvotes: 0

Views: 631

Answers (1)

Rasika
Rasika

Reputation: 1998

Change the code to:

foreach($search_exploded as $search_each) {
    //construct query
    $x++;

    if ($x==1)
        $construct .= " keywords LIKE 
            '%$search_each%' OR city LIKE '%$search_each%' or state LIKE 
            '%search_each%'";
    else
        $construct .= " OR keywords LIKE 
            '%$search_each%' OR city LIKE 
            '%$search_each%' or state LIKE '%search_each%'";
}

Upvotes: 2

Related Questions