Search Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alexmaster_2004
Forum Commoner
Posts: 35
Joined: Wed Sep 14, 2005 8:44 am

Search Problem

Post by alexmaster_2004 »

Hi
i implement a search page in my site.
i use the search page to search mysql db for products.
now i can enter the name of the product and then go to
the db and search for this product by name.
the problem is :
suppose that i have a product that its name is "Linux".
then if i write in the search box "Linux" then the query
return that product.
but what about if i write in the search box "Linu" OR "Lin"
now the query don't return any thing.
as my code is:

Code: Select all

$name = $HTTP_POST_VARS["product_name"];
$res = mysql_query("select * from products where productName like '$name' ");
$rows = mysql_num_rows($res);
if($rows != 0)
{
print "PRODUCT HAS FOUND";
}
else
{
print "PRODUCT HAS NOT FOUND";
}
i want to know how i could make the query return
the product "Linux" although i may enter "Lin" or any
similar string
Thanks in advance
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

$res = mysql_query("SELECT * FROM `products` WHERE `productName` LIKE '%$name%' ");
alexmaster_2004
Forum Commoner
Posts: 35
Joined: Wed Sep 14, 2005 8:44 am

Post by alexmaster_2004 »

Hi
i tried it but it get error.
"Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource"
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you likely have an error in your syntax or something else...

helping hint:

Code: Select all

$result = mysql_query('SELECT * FROM foo') or die(mysql_error());
alexmaster_2004
Forum Commoner
Posts: 35
Joined: Wed Sep 14, 2005 8:44 am

Post by alexmaster_2004 »

Hi
you are right.
but what about if i want to use just say 3 chars of the product name
ex: if i enter in the search box "Linux System"
i want just search by "Lin"
Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm not so sure of what you are asking...
alexmaster_2004
Forum Commoner
Posts: 35
Joined: Wed Sep 14, 2005 8:44 am

Post by alexmaster_2004 »

hi
ok i will try to explain:
i ask what about if i enter in the search box "WinXP"
how i force this search term to match with the product name "Win"
this code is not valid

Code: Select all

$res = mysql_query("SELECT * FROM `products` WHERE `productName` LIKE '%$name%' ");
it didn't return any matching.
all what i want is make it possible to get the product name "Win"
when i enter in the search "WinXP" OR "Win2000".
Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

The thing is if your going to match anything against any part the word, your going to get some pretty irrelevant matches. :?
alexmaster_2004
Forum Commoner
Posts: 35
Joined: Wed Sep 14, 2005 8:44 am

Post by alexmaster_2004 »

Hi
i'm not going to match anything against any part of the word.
but i want to make the search intelligent enough to know that
"WinXP" can match with "Win".
As i see substr() will not help me!!!!!.because i don't know
what the user will enter for search.
let's make more complex:
Assume i have a product "Real Player" in the Db.
then the user will search for "RealPlayer" how this will match???
also what about "Real Music" is this will match and how???
the problem that my DB is have a lot of products.
the user will search for some product by its name.
of-course there will be a case that the user misspell
the product name like enetr "Rael Player" then i want
to know is it possible to make them match.
i have found 2 functions soundex() and metaphone() that i think they may be useful but i don't know how????
If any ine can help me i will be pleased
Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Smee suggests using the MySQL functions for those, since it they are native to it, yar.
Post Reply