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 <[EMAIL PROTECTED]> wrote:
On 7/5/07, Kelvin Park <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> wrote:
> > On 7/5/07, Kelvin Park <[EMAIL PROTECTED]> wrote:
> > > I'm trying to build a search engine for my website (with php), it
will
> have
> > > functions such as finding product names and their codes from the
mysql
> > > database.
> > > Does anyone know any good tutorial or reference on any website, or
any
> good
> > > books out there that you might recommend?
> > > I couldnt' find any decent one but only the ones that keep on
saying,
> "use
> > > 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 =
> mysql_real_escape_string($_POST['search_data']);
> > $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-8107
> >
>
>
The example I sent to you will act as a foundation to do the first
part 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