You are here:  » Search Merchants Search Brands


Search Merchants Search Brands

Submitted by clare on Mon, 2006-10-09 13:06 in

Hi,
Is it possible to put a search box that will search the merchants, or the brands?

Say if I wanted to search the merchant names for Dixons for example, or the brands for Hotpoint?

Submitted by support on Mon, 2006-10-09 13:31

Hi Clare,

The easiest way to do this is probably to modify the existing merchants.php and brands.php to look for a query parameter ("q"), and if it exists, modify the SQL to only select items matching the search term.

For example, at the top of merchants.php is this line:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."feeds` ORDER BY merchant";

If you change that as follows:

  if ($_GET["q"])
  {
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."feeds` WHERE merchant LIKE '%".database_safe($_GET["q"])."%' ORDER BY merchant";
  }
  else
  {
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."feeds` ORDER BY merchant";
  }

...you can now pass ?q=Dixons (for example) just to show merchants matching the query. A search box to utilise this is straight forward - almost identical to the main search box with the exception of the "action" attribute of the form, and the search box title - for example:

<div class='searchform'>
  <form name='search' action='<?php print $config_baseHREF ?>merchant/'>
    <input type='text' name='q' size='35' value='<?php print (isset($q)?$q:""); ?>' />
    <input type='submit' value='Search Merchants' />
  </form>
</div>

If you do not have $config_useRewrite set to true in your config.php, you would need to change "merchant/" in the action='' attribute in the above code to "merchants.php". This is because when $config_useRewrite is set to true it expects merchant/ to be in the address bar already.

Almost the same for brands, the SQL modification required is as follows, from:

  $sql = "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` ORDER BY brand";

to:

  if ($_GET["q"])
  {
    $sql = "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` WHERE brand LIKE '%".database_safe($_GET["q"])."%' ORDER BY brand";
  }
  else
  {
    $sql = "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` ORDER BY brand";
  }

...and of course form submitting to brand/ or brands.php as required.

Cheers,
David.

Submitted by clare on Tue, 2006-10-10 11:11

Thankyou