Help - Search - Members - Calendar
Full Version: Search form Question
Pixel2Life Forum > Help Section > PHP, ASP, MySQL, JavaScript and other Web/Database Programming Help
markc1822
Hi. How are you guys, I am having a little problem with a search form i created.

I create a search form using PHP and dreamweaver it works but lets say i do a search for "photoshop" it would come up with the results that are in the database.

But, if i search for a combination of words like "photoshop water" even if its in the database it does not show the result. I can only do a search for one word at a time, not a combination of words.

here is what i have in the SQL statments. I think i have to modify something in the statement, but i am not sure where to start.

CODE
SELECT *
FROM table1
WHERE tb_title LIKE %colname% OR tb_Description LIKE %desc% OR tb_Category LIKE %cate% OR tb_author LIKE %auth% OR tb_subCat LIKE %subcat%
ORDER BY table1.id ASC


Thanks any help is appreciated

Mark
dotbart
Hi!

Well, I guess you'll have to use more OR's in your SQL statement.
The easiest to do would probably be to create the statement dynamically

CODE
$searchString = "photoshop water";

$searchTerms = explode(" ",$searchString);
$sql = "select * from table1 where ";
for($i=0;$i<sizeof($searchTerms);$i++)
{
    $sql .= "title LIKE " . $term . " OR ";
    $sql .= "description LIKE ". $term . " OR ";
    $sql .= "author LIKE " . $term;
    if($i<(sizeof($searchTerms) - 1))
    {
        $sql .= " OR ";
    }
}


Something like that would do I guess
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.