You are here:  » Displaying Featured products from specific categories only

Support Forum



Displaying Featured products from specific categories only

Submitted by MKJ on Sun, 2007-06-24 12:33 in

Hi,

We've set up a site with a few different pages (they're all basically copied front pages with different names and links to and fro). I'm trying to get it so that the first page displays only featured products whos category matches one of the category mappings.

For example, I may have a category called Computers(ie, for the homepage only) which has mappings for "Laptop Desktop Computer" etc etc.
In the products, I could have a computer with the category "Laptop", and this is a featured product.
I could also have an product with a category "Table Lamp", also a featured product but I don't want it to appear on the Computers page, just the page called Lamps.

My sql isn't too hot, but I've found the line in the .php files that goes

$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ......

I assume this can be modified so that the sql gets only those featured products that have a category in the alternates field of the categories table, whose category itself is Computers?

I've tried knocking up a quick access database, but can't get any relationships together because one is a field with a lot of words, and the other is a field with a single word, and they will never match.

Any ideas would be appreciated,

Cheers

Mike

Submitted by support on Sun, 2007-06-24 14:31

Hi Mike,

In effect, what you want is separate lists of featured products. Whilst it would be possible to create new tables in the database and create new administration pages for the new lists, it would be much easier, if you are happy to edit the source code directly, to simply change the SQL to select the products you want directly rather than have them picked from a "featured products" list.

You have correctly identified the start of the section of code that picks the featured products, which continues as follows:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ORDER BY sequence";
  if (database_querySelect($sql,$rows))
  {
    $sqlNames = array();
    foreach($rows as $featured)
    {
      $sqlNames[] = "'".$featured["name"]."'";
    }
    $sqlIn = implode(",",$sqlNames);

To specify the featured products in the code, replace all of the above as follows:

  if (1)
  {
    $sqlIn = "'Product 1','Product 2','Product 3','etc. etc.'";

You can list as many products as you want in the $sqlIn variable, and they will all be selected as featured products on that version of your home page...

Hope this helps!
Cheers,
David.

Submitted by MKJ on Tue, 2007-06-26 18:34

Hello,

Thanks for your response. After your comment about adding a new table, I had a quick look to see how difficult that would be. The person I'm editing this for has no/little programming knowledge, so it needed to be as easy to change as possible later.

I got it working with the following:
>Created a new table with the same structure as the featured table.
>Duplicated the code in the featured.php so that there is now a seperate box to enter items and add the items to the database etc (using different variable names as needed)
>Edited the second page to pull featured items from this new table instead.

And in my test environment - it seems to work!
Thanks for your help, I had thought it would be harder to achieve this!

Mike