You are here: RE: [PHP] How to search products on my site « PHP « IT news, forums, messages
RE: [PHP] How to search products on my site

Posted by Jim Moseby on 10/04/28 11:24

>
> I have a site with some phone products. I want to search for
> a specific products. I use this:
>
> SELECT product_id, product_name FROM products WHERE
> product_name LIKE '%$search_string%'
>
> It works fine if the search string counts 1 word. But if the
> search string id counts 2 or 3 or more words it's not
> working.. How can i do this kind of search. I do not want a
> boolean search or a fulltext search.

If you have decided to abandon MySQL's search functions, you will probably
need to do something like this:

$searchtype = "OR"; // Ask the user for preference 'AND' or 'OR'
$pieces=explode(' ',$searchstring);
$sql="select * from inventory where ";
foreach($pieces as $thispiece){
$sql .= "description like '%".$thispiece."%' ".$searchtype;
}

....to build a query string. Of course you will probably want to look at the
search terms for unnecessary words and definately protect yourself from SQL
injection, but this is the general idea.

>
> Thabks for any help!

Thabk you for askibg! ;-)

JM

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация