Support forum login

©2006-2012 IAAI Software

Contact Us Privacy Policy

Latest reviews on front page?

Submitted by apa on Fri, 2008-11-14 14:06.

Is there an easy way of putting the latest review on the front page?

Regards,
Anders

Submitted by support on Fri, 2008-11-14 14:20.

Hi Anders,

This can be done with some PHP that you can paste into index.php at the location required. Start with something like:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."reviews` ORDER BY created DESC LIMIT 1";
  if (database_querySelect($sql,$rows))
  {
    $review = $rows[0];
    print "<p>";
    if ($config_useRewrite)
    {
      $href = $config_baseHREF."product/".tapestry_hyphenate($review["product_name"])."/";
    }
    else
    {
      $href = $config_baseHREF."products.php?q=".urlencode($review["product_name"]);
    }
    print "<a href='".$href."'>".$review["product_name"]."</a>";
    print "<br />";
    print $review["comments"];
    print "</p>";
  }

Cheers,
David.

Submitted by apa on Fri, 2008-11-14 14:36.

Thanks, it works! :-)

Changing the limit from 1 to anything makes no difference. Could it display say 2 or 3 reviews instead of 1?

Thanks for all your answers - i know i've had a lot of questions lately,
Anders

Submitted by support on Fri, 2008-11-14 17:00.

Hi Anders,

The above code is specific to a single result as it does not include a foreach() loop on the results of the query. Here's a version that will display any number of results:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."reviews` WHERE approved > 0 ORDER BY created DESC LIMIT 1";
  if (database_querySelect($sql,$rows))
  {
    foreach($rows as $review)
    {
      print "<p>";
      if ($config_useRewrite)
      {
        $href = $config_baseHREF."product/".tapestry_hyphenate($review["product_name"])."/";
      }
      else
      {
        $href = $config_baseHREF."products.php?q=".urlencode($review["product_name"]);
      }
      print "<a href='".$href."'>".$review["product_name"]."</a>";
      print "<br />";
      print $review["comments"];
      print "</p>";
    }
  }

Cheers,
David.

Submitted by apa on Sun, 2008-11-16 10:43.

Hi David

It work well except that it shows unconfirmed reviews as well. Can you exclude them somehow?

Submitted by support on Sun, 2008-11-16 10:47.

Hi Anders,

I've fixed this in the code above - just changing:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."reviews` ORDER BY created DESC LIMIT 1";

to:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."reviews` WHERE approved > 0 ORDER BY created DESC LIMIT 1";

Cheers,
David.

Submitted by apa on Sun, 2008-11-16 11:59.

Super, thanks.

I have just one more thing. I was trying to put in the code for showing star ratings...

<?php
 
print tapestry_stars($product["rating"],"s"); 
?>

I allway tries to load the "0s.gif" image though.

Maybe it is'nt possible?

Thanks,
Anders

Submitted by support on Sun, 2008-11-16 15:02.

Hi Anders,

You need to use $review["rating"] rather than $product["rating"] at that point in the code...

Cheers,
David.

Submitted by HJW on Wed, 2008-12-03 16:39.

Hi David,
I've implemented this mod on my site and it works very well. Is there any way of limiting the reviews on display, to say, the first 50 words?

Kind Regards

Hayden

Submitted by support on Wed, 2008-12-03 16:48.

Hi Hayden,

Sure, it's easier to break it down by number of characters, but it's easy to make sure the break is on a space and not the middle of a word. Try replacing this line from the mod:

    print $review["comments"];

...with this code:

    $breakLimit = 250;
    if (strlen($review["comments"]) > $breakLimit)
    {
      // find the first space after the limit
      $breakOffset = strpos($review["comments"]," ",$breakLimit);
      // if found, crop the description and add "..."
      if ($breakOffset !== false)
      {
        $review["comments"] = substr($review["comments"],0,$breakOffset)."...";
      }
    }
    print $review["comments"];

...just change the value of $breakLimit to the length required!

Cheers,
David.

Submitted by HJW on Wed, 2008-12-03 16:53.

Cheers David,
Excellent

Kind Regards
Hayden

Submitted by gunneradt on Thu, 2008-12-04 23:48.

Ive tried this on my site but the title of the review - namely the product name doesn't link to the product as it seems to be mising .html

have i done it incorrectly?

Submitted by gunneradt on Thu, 2008-12-04 23:51.

it's ok fixed it by adding .html to the code

cheers

Submitted by gunneradt on Fri, 2008-12-05 00:07.

OK

Ive got the product name and comments working

I'd like the number of stars to show beside the product name

where in that code do I put?

<?php
 
print tapestry_stars($product["rating"],"s");
?>

cheers

Submitted by support on Fri, 2008-12-05 10:04.

Hi,

If you wanted to display the stars alongside the product name, you could replace:

    print "<a href='".$href."'>".$review["product_name"]."</a>";

...with:

    print "<a href='".$href."'>".$review["product_name"]."</a>&nbsp;".tapestry_stars($review["rating"],"s");

Notice that I have changed the variable name to $review instead of $product...

Cheers,
David.

Submitted by gunneradt on Fri, 2008-12-05 12:45.

perfect

thank you

Submitted by FirstByte on Wed, 2009-07-22 14:24.

Hi David,

Great mod, I've got it all working but have been trying to add one last touch. To display the image of the product that has the review.

I've tried using the $review["image_url"] variable (or array not sure which it is) but i can't seem get anything to display.

$product["image_url"] did display the image unfortunately it displayed the last image from the feature listing.

Can this be added to current examples?

Cheers
Rod

Submitted by support on Wed, 2009-07-22 14:48.

Hi Rod,

image_url isn't part of the reviews table, so what you'd need to do is SELECT it from the products table within the loop, i.e. look for the following code:

    foreach($rows as $review)
    {

...and REPLACE this as follows:

    foreach($rows as $review)
    {
      $sql2 = "SELECT image_url FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($review["product_name"])."' AND image_url <> '' LIMIT 1";
      database_querySelect($sql2,$rows2);
      $review["image_url"] = $rows2[0]["image_url"];

Then you can use $reviews["image_url"] as you were trying to do, but I would recommend enclosing your code for the image within an IF statement so that you only generate the HTML if there is an image_url, for example:

  if ($review["image_url"])
  {
    // ...generate image HTML here...
  }

Cheers,
David.

Submitted by FirstByte on Thu, 2009-07-23 23:38.

Hi David,

I get the following message "Parse error: syntax error, unexpected T_STRING in /home/shopther/public_html/html/featured.php on line 74"

I've integrated the code below into the featured.php page at the bottom.

line 74 start here "database_querySelect($sql2,$rows2);"

Have I missed a closing bracket somewhere?

<?php
   $sql = "SELECT * FROM `".$config_databaseTablePrefix."reviews` WHERE approved > 0 ORDER BY created DESC LIMIT 5";
  if (database_querySelect($sql,$rows))
  {
 foreach($rows as $review)
    {
      $sql2 = "SELECT image_url FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($review["product_name"])."' AND image_url <> '' LIMIT 1"
      database_querySelect($sql2,$rows2);
      $review["image_url"] = $rows2[0]["image_url"];
      print "<p>";
      if ($config_useRewrite)
      {
        $href = $config_baseHREF."product/".tapestry_hyphenate($review["product_name"]).".html";
      }
      else
      {
        $href = $config_baseHREF."products.php?q=".urlencode($review["product_name"]);
      }
        $comments = unserialize($review["comments"]);
        print "<em>";
        print $comments["date"];
        print "</em> ";
        print "<br/>";
        print "<strong> ".$comments["name"];
        print " </strong> purchased <a href='".$href."'>".$review["product_name"]."</a> from <strong> ".$comments["purchased"];
        print " </strong> [".$review["image_url"]."] [".$product["image_url"]."]<br/>";
        print "<br/>";
if ($review["image_url"])
   {
print "<img src='http://shoptherapy.com.au/imageCache.php?src=".$review["image_url"]."' align='left' border='1' alt=' ' hspace='2' vspace='2'>";
   }
    else
    {
         print "<img width='40' height='40' src='http://shoptherapy.com.au/images/no_image.jpg' alt='No Image for <?php print $product["merchant"]; ?>' border='0'>";
    }
        print "<div class='StarRating'>Overal Rating</div> <div style='float:left'> : ";
        print tapestry_stars($review["rating"],"");
        print "</div><br/>";
        print "<div class='StarRating'>Ease of Use </div> <div style='float:left'>: ".tapestry_stars($comments["ease"],"")."";
        print "</div><br/>";
        print "<div class='StarRating'>Product Design</div> <div style='float:left'>: ".tapestry_stars($comments["design"],"")."";
        print "</div><br/>";
        print "<div class='StarRating'>Material and Quality </div> <div style='float:left'>: ".tapestry_stars($comments["quality"],"")."";
        print "</div><br/>";
        print "<br/>";
$breakLimit = 250;
if (strlen($comments["comments"]) > $breakLimit)
{
// find the first space after the limit
$breakOffset = strpos($comments["comments"]," ",$breakLimit);
// if found, crop the description and add "..."
if ($breakOffset !== false)
{
$comments["comments"] = substr($comments["comments"],0,$breakOffset)."...";
}
     }
        print "".$comments["comments"];
        print "<br/><br/>";
        print "<div style=' clear:both; height:5px; border-bottom:1px dashed #dcdcdc; margin-bottom: 10px;' ></div>";
    }
  }
  ?>

Submitted by support on Fri, 2009-07-24 07:37.

Hi Rod,

Sorry - i'd missed the ; off this line in my original post;

$sql2 = "SELECT image_url FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($review["product_name"])."' AND image_url <> '' LIMIT 1"

...which should of course be;

$sql2 = "SELECT image_url FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($review["product_name"])."' AND image_url <> '' LIMIT 1";

I've corrected my original post above also.

Cheers,
David.

Submitted by FirstByte on Wed, 2009-07-29 01:50.

That worked a treat.