You are here:  » featured products shown on home page

Support Forum



featured products shown on home page

Submitted by clare on Wed, 2010-08-18 13:03 in

Hi,

Recently the php version on server was upgraded to PHP version 5.2.11

It had featured products showing on the home page from two databases, shopUK & shopUSA products.

I am getting errors and wondered if anyone could help me get the featured products code on my site working again with the new version of php.

This is the code I was using on index.htm, the shopUSA featured products were showing just fine, but the shopUK featured products returned an error.

<?php
  $path = "shopUK/";
  require($path."config.php");
  require($path."includes/"."javascript.php");
  require($path."includes/"."tapestry.php");
  require($path."includes/"."translate.php");
  require($path."includes/"."database.php");
  $seed = intval(date("Ymd"));
 //start of new random code
   $sql = "SELECT merchant FROM `".$config_databaseTablePrefix."feeds` ORDER BY RAND() LIMIT 1";
  database_querySelect($sql,$result);
  $merchant = $result[0]["merchant"];
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE merchant='".database_safe
($merchant)."' ORDER BY RAND() LIMIT 6";
 // ORIG $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 4";
  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);
    // the 4 random featured products with all product data etc. are now in $rows
    $featured["products"] = $rows;
    foreach($featured["products"] as $k => $product)
    {
      if ($config_useRewrite)
      {
        $featured["products"][$k]["productHREF"] = $config_baseHREF."product/".tapestry_hyphenate
($product["name"]).".html";
        $featured["products"][$k]["reviewHREF"] = $config_baseHREF."review/".tapestry_hyphenate
($product["name"]).".html";
      }
      else
      {
        $featured["products"][$k]["productHREF"] = $config_baseHREF."products.php?q=".urlencode
($product["name"]);
        $featured["products"][$k]["reviewHREF"] = $config_baseHREF."reviews.php?q=".urlencode
($product["name"]);
      }
    }
  }
  require($path."html/"."featured.php");
?>
              </p>
              </p>
         <p>
                <?php
  $path2 = "shopUSA/";
  require($path2."config.php");
  $seed = intval(date("Ymd"));
 //start of new random code
   $sql = "SELECT merchant FROM `".$config_databaseTablePrefix."feeds` ORDER BY RAND() LIMIT 1";
  database_querySelect($sql,$result);
  $merchant = $result[0]["merchant"];
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE merchant='".database_safe($merchant)."' ORDER BY RAND() LIMIT 6";
 // ORIG $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 4";
  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);
    // the 4 random featured products with all product data etc. are now in $rows
    $featured["products"] = $rows;
    foreach($featured["products"] as $k => $product)
    {
      if ($config_useRewrite)
      {
        $featured["products"][$k]["productHREF"] = $config_baseHREF."product/".tapestry_hyphenate($product["name"]).".html";
        $featured["products"][$k]["reviewHREF"] = $config_baseHREF."review/".tapestry_hyphenate($product["name"]).".html";
      }
      else
      {
        $featured["products"][$k]["productHREF"] = $config_baseHREF."products.php?q=".urlencode($product["name"]);
        $featured["products"][$k]["reviewHREF"] = $config_baseHREF."reviews.php?q=".urlencode($product["name"]);
      }
    }
  }
  require($path2."html/"."featured.php");
?>

Thanks

Submitted by support on Wed, 2010-08-18 13:15

Hi Clare,

As the second section works fine, I'm assuming that the error message displayed by the first section is a result of the default error_level being turned up to the max on your new PHP installation, resulting in a warning regarding uninitialised variables. The first thing I would try is to turn down the warning level in this script as follows (at the top);

<?php
  error_reporting
("E_ERROR");
?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by clare on Wed, 2010-08-18 16:26

Thanks David,

That has stopped the error message from showing that was previously displayed, but the code is still not showing the UK featured products.

It is odd because the code in featured.php in shopUSA is same as code in shopUK file, but the error message was saying
that there is an error in featured.php on line 14.

So I am thinking it must be something else, but cant figure out what.

Submitted by support on Wed, 2010-08-18 18:54

Hi Clare,

Could you email me your html/featured.php and also your index page, and perhaps if you could try an experiment - to swap over the sections, so that the USA code appears first, and see if the situation is reversed...

Cheers,
David.
--
PriceTapestry.com