You are here:  » Product random and picture

Support Forum



Product random and picture

Submitted by boussole on Thu, 2007-03-22 00:19 in

Hi,

Firstly, thanks for the script !
Sorry for my english but I'm frog !

- I would like many random products on all pages (about 5) ?

- When there are many products to compare, there are just one picture ($mainProduct=$mainPicture), I would like each product have its picture ?

Thank you for your help
Best regards

Submitted by support on Thu, 2007-03-22 08:54

Hi there,

To display random products, you can use the same code as used to display the featured products on the home page, but changing the SQL to pick random products instead of the ones from the featured products table.

This is the code:

<?php
  $sql 
"SELECT name FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 5";
  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");
?>

If you want to include that on every page simply paste this into your html/footer.php or layout as required.

To display the picture for all products on the prices table and not just the main product you can simply add a column to the table to contain the image.

In html/prices.php look for the following:

<th align='left'><?php print translate("Catalogue Product Name"); ?></th>

...and add the following code on the next line:

<th align='left'><?php print translate("Image"); ?></th>

Then lower down the same file, look for:

<td><?php print $product["name"]; ?></td>

...and add the following code:

<td><img border='0' width='80' src='<?php print $product["image_url"]; ?>' /></td>

Hope this helps!
Cheers,
David.

Submitted by boussole on Thu, 2007-03-22 09:46

Thak you very much for your helps David, all is ok !