You are here:  » Automatic updating of featured products

Support Forum



Automatic updating of featured products

Submitted by tbbd2007 on Tue, 2008-03-04 19:35 in

David,

I am using

  $sql = "SELECT name FROM products ORDER BY clicks DESC LIMIT 10";
  if (database_querySelect($sql,$rows))
  {
    foreach($rows as $row)
    {
      if ($config_useRewrite)
      {
        $url = $config_baseHREF."product/".tapestry_hyphenate($row["name"]).".html";
      }
      else
      {
        $url = $config_baseHREF."products.php?q=".urlencode($row["name"]);
      }
      print "<br><a href='".$url."'>".$row["name"]."</a>";
    }
  }
to display the top ten products and wondered whether there was some way to post these results on the fly to the featured products table so that the featured products displayed on the homepage are the current top ten products as queried by the code above.

Thanks

Stephen Elcombe
Online Shopping For
The Big Business Directory

Submitted by support on Tue, 2008-03-04 20:47

Hi Stephen,

The queries to update the featured products based on the result of the query above can certainly be inserted into the above code, but I just want to check - what page is the above code running on? Is it within index.php and displayed alongside featured products? Just want to make sure I understand the requirement...

Cheers,
David.

Submitted by tbbd2007 on Tue, 2008-03-04 20:53

David,

Yes, this code is on index.php. I was thinking that I could display the top ten products as featured products, rather than having them as text links.

Thanks,

Stephen

Submitted by support on Tue, 2008-03-04 20:59

Hi Stephen,

That's what I wanted to check - because if you just want to replace the featured products with the Top 10 as derived from the query in the above code, then you can simply replace the Featured Products query with the Top 10 query - there's no need to update the featured products database table to do this.

Currently, the Featured Products (just their names) are selected by the SQL genereted by the following code on line 32 of index.php

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ORDER BY sequence";

You can simply replace this with:

  $sql = "SELECT name FROM products ORDER BY clicks DESC LIMIT 10";

...and that should do the trick!

Cheers,
David.