Shopping Cart Tutorial PHP Shopping Cart Tutorial
Learn how to create an online store with PHP and MySQL
Free shopping cart    Download:
Shop-Script FREE
Shop-Script FREE User Guide (PDF; 0 Kb)
View Live Demo    View online store demo
 Introduction
 Basic concepts
 Technologies
 File structure
 Database structure
 Back end
   Password protection
   Products catalog: structure
   Product catalog: viewing
   Managing categories
   Managing products
   Special offers
   Managing orders
 Front end
   Viewing products catalog
   Product search
   Shopping cart
   Checkout
   PayPal integration
 Security
 Live Demo
 Author
 Terms Of Use

Shopping cart software

 

Products search

Product search function can be implemented easier than one can imagine (here I only review the very basic product search facility - search for conclusion of a search term in the product information). It requires only a small search form and executing a single SQL-query.

This is the form HTML template (search_form.tpl.html):

<form action="index.php" method="get">

<tr>
<td>Search:</td>
<td><input type="text" name="searchstring" size="7" value=""></td>
<td><input type="image" border="0" src="images/search.gif"></td>
</tr>

</form>

When this form is submited, product search is performed using a SQL query (includes/search_simple.php):

SELECT * FROM `PRODUCT` WHERE Enabled=1 AND (name LIKE '%".$_GET["searchstring"]."%' OR description LIKE '%".$_GET["searchstring"]."%' OR brief_description LIKE '%".$_GET["searchstring"]."%');

This query will return a list of products matching the search criteria.

Please note that the query presented above is just an example. You should keep in mind that you have to validate input $_GET data before executing a query (with mysql_escape_string() functions, for example). Please refer to Security section for more details.

If you would like to highlight search criteria when displaying search results you can simply add such Smarty modifiers in product templates (this is an example with the product name - this technique makes search string conclusions bold):

{$product_name|replace:"$searchstring":"<b>$searchstring</b>"}

In Shop-Script FREE search results highlighting is not implemented by default, but you can easily add such facility by editing product_brief.tpl.html and product_detailed.tpl.html template files.

Please note that in Shop-Script FREE product search facility is a bit more complex - see includes/search_simple.php source file for more information.

 

 


Copyright © 2006 WebAsyst LLC