Re: About Website Search Engine
| From: | Nathan Nobbe | Date: | Fri, 06 Jul 2007 02:26:20 +0000 |
| Subject: | Re: About Website Search Engine | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-258384@lists.php.net to get a copy of this message | ||
Kevin,
just like Daniel said,
$sql .= "OR product_description *LIKE '%".$terms."%'"*;most of the *search engines* ive seen revolve around the use of the LIKE construct<http://dev.mysql.com/doc/refman/5.1/en/string-comparison-functions.html#operator_like> which is a simplified regex mechanism for an SQL query [for MySQL at least, probly other RDBMS' as well] -nathan On 7/5/07, Daniel Brown <parasane@gmail.com> wrote:
On 7/5/07, Kelvin Park <kelvinpark86@gmail.com> wrote: Yes my website is dynamically driven from content within mysql. The products and the product information is within the datase. I was looking for a way to allow people to "efficiently" search for an item, for example if a customer types in, "bunny", it would find everything (and display them) that has word "bunny", or if the customer "misspells" it, "bunn", it will still display every item with the letters accordingly. On 7/5/07, Daniel Brown <parasane@gmail.com> wrote:On 7/5/07, Kelvin Park <kelvinpark86@gmail.com> wrote:will haveI'm trying to build a search engine for my website (with php), itmysqlfunctions such as finding product names and their codes from theany gooddatabase. Does anyone know any good tutorial or reference on any website, orsaying, "usebooks out there that you might recommend? I couldnt' find any decent one but only the ones that keep onmysql_real_escape_string($_POST['search_data']);google search engine to search your website!" etc. Thanks!Kelvin, That depends. Is the content of your website dynamically-driven from content within the MySQL database you mentioned? If so, something like this would work: <? // Do your includes and database connection schemes here. if($_POST['search_data']) { $terms =$sql = "SELECT * FROM tablename WHERE $terms IN "; $sql .= "product_id,product_name,product_description"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) {extract($row); // Do your processing of each row of information here.} } ?> <FORM METHOD="POST" ACTION="<?=$_SERVER['PHP_SELF'];?>"> Terms: <INPUT TYPE="TEXT" NAME="search_data" VALUE="<?=$_POST['search_data'];?>"><BR /> <INPUT TYPE="SUBMIT" VALUE="Search"> </FORM> -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107The example I sent to you will act as a foundation to do the firstpart of what you're asking, but not the second. To do something like the second, you'll want to do something like:$sql = "SELECT * FROM tablename WHERE $terms IN "; $sql .= "product_id,product_name,product_description "; $sql .= "OR product_description LIKE '%".$terms."%'";-- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php