You are here:  » how to order the feature products ?

Support Forum



how to order the feature products ?

Submitted by darkstar_tfd on Tue, 2008-04-01 04:37 in

How should I order my feature products by the way I list them on the admin panel ? I know I read it should be automaticly done ( it is ordered by sequence ), still, the products do not appear as I would like them to do.

I have done some changes a while ago on the index.php ( I think ) to order the prods on 3 rows. Here is the code:

$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);
    $sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$sqlIn.") GROUP BY name";
    database_querySelect($sql,$rows);
    $featured["products"] = $rows;
    foreach($featured["products"] as $k => $product)
    {
      if ($config_useRewrite)
      {
        $featured["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($product["name"]).".html";
        $featured["products"][$k]["reviewHREF"] = "review/".tapestry_hyphenate($product["name"]).".html";
      }
      else
      {
        $featured["products"][$k]["productHREF"] = "products.php?q=".urlencode($product["name"]);
        $featured["products"][$k]["reviewHREF"] = "reviews.php?q=".urlencode($product["name"]);
      }
    }
  }
  if (isset($featured)) require("html/featured.php");

Would you also need the featured.php file code ?

Thank you

Submitted by support on Tue, 2008-04-01 11:05

Hi,

I have come across this before, and is to do with the way MySQL is returning the results of the second query, as in some configurations it does not retrieve rows in the order of the items in the IN clasue. To fix this, use the modified version of the block of code you posted below...

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ORDER BY sequence";
  if (database_querySelect($sql,$rows))
  {
    $sqlNames = array();
    $sqlCase = "CASE name";
    foreach($rows as $featured)
    {
      $sqlNames[] = "'".$featured["name"]."'";
      $sqlCase .= " WHEN '".database_safe($featured["name"])."' THEN ".$featured["sequence"];
    }
    $sqlCase .= " END AS sequence";
    $sqlIn = implode(",",$sqlNames);
    $sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, ".$sqlCase." FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$sqlIn.") GROUP BY name ORDER BY sequence";
    database_querySelect($sql,$rows);
    $featured["products"] = $rows;
    foreach($featured["products"] as $k => $product)
    {
      if ($config_useRewrite)
      {
        $featured["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($product["name"]).".html";
        $featured["products"][$k]["reviewHREF"] = "review/".tapestry_hyphenate($product["name"]).".html";
      }
      else
      {
        $featured["products"][$k]["productHREF"] = "products.php?q=".urlencode($product["name"]);
        $featured["products"][$k]["reviewHREF"] = "reviews.php?q=".urlencode($product["name"]);
      }
    }
  }
  if (isset($featured)) require("html/featured.php");

That should do the trick!

Cheers,
David.

Submitted by darkstar_tfd on Wed, 2008-04-02 06:05

Thanks very much, I appreciate the help !

One of the best support I have received was here :-)

Submitted by FirstByte on Wed, 2009-03-25 20:34

Hi David,

I currently have the feature products listed across in 4 columns table and would like to add more feature products without increasing the table width.

How would I be able to create a new row after every 4th feature product?

regards
Rod

Submitted by support on Wed, 2009-03-25 20:41

Hi Rod,

Checkout the following thread for a simple mod to show Featured Products in rows...

http://www.pricetapestry.com/node/284

Cheers,
David.

Submitted by FirstByte on Fri, 2009-03-27 23:23

Thanks, that works a treat.

Rod