You are here:  » Newest products on the main page?


Newest products on the main page?

Submitted by Peter on Sat, 2006-08-12 09:37 in

Hello David,

i work since days on a script who shows me the 5 newest products on the main page like as the featerd products, but for my left frame, where is now the ad from amazon.

Here my new site

I took the 5 latest entries from the database, but nothing happend :)

Have you any idea?

Thanks a lot, Peter

Submitted by support on Sat, 2006-08-12 11:17

Hi Peter,

What code did you use? It should probably be something like this:

<?php
  $sqlNames 
= array();
  
$sql "SELECT name FROM `".$config_databaseTablePrefix."products` ORDER BY id DESC LIMIT 5";
  
database_querySelect($sql,$rows);
  foreach(
$rows as $row)
  {
    
$sqlNames[] = $row["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"]);
    }
  }
  require(
"html/featured.php");
?>

You might also find the following thread interesting with some other ideas for showing featured products:

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

Cheers,
David.