You are here:  » search and show only selected brands


search and show only selected brands

Submitted by rolli1 on Mon, 2006-10-09 23:20 in

Hi David,

I have a feed with about 1000 brands. I want to search only some selected brands and show their products.

Is there a way to do this?

Regards

Roland

Submitted by support on Tue, 2006-10-10 08:49

Hi Roland,

With that many brands it would not be practical to offer a user input to select multiple brands; but you could do something if you just wanted to display a fixed set of search results for pre-selected brands? Is that what you want to do?

Cheers,
David.

Submitted by rolli1 on Tue, 2006-10-10 14:04

Exactly that's what I want to to. Sorry.

Regards
Roland

Submitted by rolli1 on Wed, 2006-10-11 09:48

Any help, how I can manage that?

Regards

Roland

Submitted by support on Wed, 2006-10-11 12:55

Hi Roland,

Let's say you want to create a saved search to select all products with the brands "Sony", "Panasonic" and "Hitachi". Firstly, think of a name for this search, for example "sph". Now, you need to add code for this saved query to search.php. The format I would suggest would be to support a query URL something like this:

search.php?q=saved:sph:

The code to support this would need to be added into search.php immediately after the following code (at line 37):

    switch($parts[0])
    {

The code would look like this:

      case "saved":
        if ($parts[1] == "sph")
        {
          $where = "brand='Sony' OR brand='Panasonic' OR brand='Hitachi'";
          $sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE ".$where." GROUP BY name";
          $sqlResultCount = "SELECT COUNT(DISTINCT(name)) as resultcount FROM `".$config_databaseTablePrefix."products` WHERE ".$where;
          $orderBySelection = $orderByDefault;
        }
        break;

To create more saved searches, simply add more if ($parts[1] == "xxx") blocks to this section of code.

To link to this saved search, you simply need to add code something like the following to your index.php (or any other page)...

<a href='/search.php?q=saved:sph:'>Click here for the latest products from Sony, Panasonic and Hitachi</a>

Don't forget that if your site is not installed in the root directory of your website you will need to put the path to your site infront of /search.php...

Hope this helps!
Cheers,
David.

Submitted by rolli1 on Wed, 2006-10-11 13:23

Thank you so much.

Greetings

Roland

Submitted by rolli1 on Wed, 2006-10-11 23:20

Hi David a last question concerning that issue: Is it possible to restrict the saved search to a single merchant?

Regards

Roland

Submitted by support on Thu, 2006-10-12 07:40

Sure - simply extend the WHERE clause, so instead of:

$where = "brand='Sony' OR brand='Panasonic' OR brand='Hitachi'";

...use something like this:

$where = "merchant='Foo' AND (brand='Sony' OR brand='Panasonic' OR brand='Hitachi')";

Notice the brackets around the brand statments; this is required so that you only select products where the merchant is Foo _and_ the brand is one of those listed.

Cheers,
David.

Submitted by rolli1 on Thu, 2006-10-12 09:42

Thanks, it works fine, also the adding of more saved searches.

ROland