Re: How to do freeform text search across multiple fields ??

From: Date: Sun, 25 Jan 2004 08:44:10 +0000
Subject: Re: How to do freeform text search across multiple fields ??
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-32616@lists.php.net to get a copy of this message
What I wanna do is make it possible to search for partial content in model,variant, and type fields, all 3 at the same time, or each individually as the user wants...case insentive too ...
<? //assuming you got a POST from the form :) reset ($_POST); while (list ($key, $val) = each ($_POST)) {
        $$key = $val;
} if(!(empty($model))) {
        $searchstring .= " AND model LIKE '$model'";
} if(!(empty($variant))) {
        $searchstring .= " AND variant LIKE '$variant'";
} if(!(empty($fields))) {
        $searchstring .= " AND fields LIKE '$fields'";
} $query = "SELECT * FROM cpu WHERE cpuID <> '0' $searchstring ORDER BY cpuID"; $connection = mysql_connect($HOST, $USERNAME, $PASSWORD); $SelectedDB = mysql_select_db($DBNAME); $result = mysql_query($query); //etc. ?> It's a bit quick and dirty, because you need something like the cpuID <> '0' to make this to work. But its a start right ;) laters, Fedde ~= The sum of the intelligence on the planet is a constant; the population is growing. =~

« previous php.db (#32616) next »