RE: [PHP-DB] Help Please! Complex AND OR LIKE queries MySQL/PHP

From: Date: Tue, 18 Sep 2001 12:55:30 +0000
Subject: RE: [PHP-DB] Help Please! Complex AND OR LIKE queries MySQL/PHP
Groups: php.db 
Request: Send a blank email to php-db+get-12543@lists.php.net to get a copy of this message
Cheers Rick ... I think I nailed it. I've copied my little function below for anyone else interested. Am keen on the "saving milliseconds" bit, though (will add it to the function below before making it live). Any more tips? Dave function parse($what) { $what = strtolower($what); $what = ltrim($what); $what = rtrim($what); $wa = explode(" ",$what); for ($i=0; $i<= sizeof($wa); $i++) { if (strlen($wa[$i]) !==0) { $j = $i + 1; if ($wa[$i] == "or") { $output .= " OR search_column LIKE '%$wa[$j]%' "; $i++; } elseif ($wa[$i] == "and") { $output .= " AND search_column LIKE '%$wa[$j]%' "; $i++; } elseif ($wa[$i] == "not") { $output .= " AND search_column NOT LIKE '%$wa[$j]%' "; $i++; } else { $output .= " AND search_column LIKE '%$wa[$i]%' "; } } } // strip leading AND from every option $output = substr($output, 4, strlen($output)-3); $what = $output; return $what; }

« previous php.db (#12543) next »