note 13883 deleted from function.split by jeroen
| From: | jeroen@php.net | Date: | Wed, 29 Aug 2001 17:41:01 +0000 |
| Subject: | note 13883 deleted from function.split by jeroen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-17328@lists.php.net to get a copy of this message | ||
I found strstr and strtok before finding split(), but I've manipulated it to make it a viable
alternative. The code below splits a variable $name into two components, and then run's queries
based on the user's input whether they type in the first name, the last name, or both, in any
order, to find search results. This is much more accurate than a normal search I think. $noresult
merely returns 'no results found' on my search. Enjoy!
$token = strtok($name, " ");
$length = strlen($token);
$partone = substr($name,0,$length);
$parttwo = substr($name,$length+1);
echo $partone . "<BR>" . $parttwo ;
$result = mysql_query("SELECT * FROM customers where name LIKE '%$partone%' OR name
LIKE '%$parttwo%' ");
if (strlen($parttwo) == 0) { $result = mysql_query("SELECT * FROM customers where name
LIKE '%$partone%'"); };
if (strlen($name) == 0) { echo $noresult; die; };
echo "Possible Matches Found: " . mysql_num_rows($result) . "<BR>";
if (mysql_num_rows($result) == 0) { echo $noresult; };
while ($row = mysql_fetch_object($result)){
$row++;