Forum Moderators: coopster

Message Too Old, No Replies

search item in database

         

kristof_v

10:57 am on Feb 17, 2006 (gmt 0)

10+ Year Member



hi all,

i made a function that does a case insensitive search.
this works fine.
but i'd like to improve that script so that it also returns items from the database that are partly similar to the search string.

this is the script atm:
-----------------------

$name = $_POST['name'];
$ucfirst_name = htmlspecialchars(stripslashes(ucfirst(strtolower($name))));
$search = mysql_query("select id, naam, type_id, merk_id from producten where naam='".$ucfirst_name."'");

how can i modify this so that it finds items that are partly similar to the search string?
for example:
let's say that we would like to find an item called DIGI-X10 and we enter a search string of digi

grtz

zCat

11:01 am on Feb 17, 2006 (gmt 0)

10+ Year Member



Use LIKE and the % operator, e.g.

select id, naam, type_id, merk_id from producten where naam LIKE '%digi%'

This is not very efficient though, if you have a very large dataset you'll need to look at fulltext indexing.

omoutop

11:05 am on Feb 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use

$search = mysql_query("select id, naam, type_id, merk_id from producten where naam LIKE '%".$ucfirst_name."%'");

I think this should work

kristof_v

11:42 am on Feb 17, 2006 (gmt 0)

10+ Year Member



yop that did the trick!

thx guys