You are here:  » Reviews in search results

Support Forum



Reviews in search results

Submitted by wilkins on Fri, 2007-04-20 11:48 in

Hi

At present the star rating is shown in the search results, is there any way to show the actual reviews for the products in the search results also. The reason being, i am trying to get as much info on these pages so it cuts down the number of clicks the customer needs to get the the affiliate pages.

Thanks

Brent

Submitted by support on Fri, 2007-04-20 12:01

Hi Brent,

Yes - that's reasonably straight forward to do. It's basically an SQL query to read the reviews for each product in the search results, and then the HTML code borrowed from the main review page to display them.

Here's a replacement html/searchresults.php to demonstrate:

<?php
  if (file_exists("html/user_searchresults_before.php")) require("html/user_searchresults_before.php");
?>
<div class='searchresults'>
  <table width='100%'>
    <?php foreach($searchresults["products"] as $product): ?>
      <tr>
        <td>
          <?php if ($product["image_url"]): ?>
          <a href='<?php print $product["productHREF"]; ?>'><img border='0' width='80' src='<?php print $product["image_url"]; ?>' alt='<?php print $product["name"]; ?>' /></a>
          <?php endif; ?>
        </td>
        <td width='50'>&nbsp;</td>
        <td valign='middle'>
          <?php if ($config_useInteraction): ?>
          <h4><a href='<?php print $product["productHREF"]; ?>'><?php print $product["name"]; ?></a> <?php if ($product["rating"]) print tapestry_stars($product["rating"],""); ?></h4>
          <?php else: ?>
          <h4><a href='<?php print $product["productHREF"]; ?>'><?php print $product["name"]; ?></a></h4>
          <?php endif; ?>
          <p><?php print substr($product["description"],0,250); ?></p>
          <?php
          $sql = "SELECT * FROM `".$config_databaseTablePrefix."reviews` WHERE product_name = '".database_safe($product["name"])."' AND approved <> '0' ORDER BY created";
          if (database_querySelect($sql,$rows))
          {
            ?>
            <table width='100%' cellpadding='4'>
              <tr bgcolor='#eeeeee'>
                <th width='100' align='left'><?php print translate("Rating"); ?></th>
                <th align='left'><?php print translate("Comments"); ?></th>
              </tr>
              <?php foreach($rows as $review): ?>
              <tr>
                <td align='center' bgcolor='#ffffcc'>
                  <?php print tapestry_stars($review["rating"],""); ?>
                </td>
                <td>
                  <?php if ($review["comments"]): ?>
                  <?php print htmlentities($review["comments"],ENT_QUOTES,$config_charset); ?>
                  <?php else: ?>
                  <em><?php print translate("This reviewer did not leave any comments."); ?></em>
                  <?php endif; ?>
                </td>
              </tr>
              <?php endforeach; ?>
            </table>
            <?php
          }
          ?>
        </td>
        <td width='50'>&nbsp;</td>
        <td valign='middle' align='center'>
          <?php if ($product["numMerchants"] > 1): ?>
            <em><?php print translate("from"); ?></em>&nbsp;<strong><?php print $config_currencyHTML.$product["minPrice"]; ?></strong><br />
            <span class='nobr'><a href='<?php print $product["productHREF"]; ?>'><?php print translate("Compare Prices"); ?></a></span>
          <?php else: ?>
            <strong><?php print $config_currencyHTML.$product["price"]; ?></strong><br />
            <span class='nobr'><a href='<?php print $product["productHREF"]; ?>'><?php print translate("More Information"); ?></a></span>
          <?php endif; ?>
        </td>
      </tr>
    <?php endforeach; ?>
  </table>
</div>
<?php
  if (file_exists("html/user_searchresults_after.php")) require("html/user_searchresults_after.php");
?>

It might be worth using a smaller font for the review text in this version - see what you think.

Hope this helps!
Cheers,
David.

Submitted by wilkins on Fri, 2007-04-20 19:02

Hi david

That works great, one quick question, what would be the code to put a link on the search page to the review page for the product..

Thnanks

Brent

Submitted by support on Fri, 2007-04-20 20:01

Hi Brent,

Just a little more code - have a look at the new version below; in between the closing } and the closing PHP tags of the previous modification:

<?php
  if (file_exists("html/user_searchresults_before.php")) require("html/user_searchresults_before.php");
?>
<div class='searchresults'>
  <table width='100%'>
    <?php foreach($searchresults["products"] as $product): ?>
      <tr>
        <td>
          <?php if ($product["image_url"]): ?>
          <a href='<?php print $product["productHREF"]; ?>'><img border='0' width='80' src='<?php print $product["image_url"]; ?>' alt='<?php print $product["name"]; ?>' /></a>
          <?php endif; ?>
        </td>
        <td width='50'>&nbsp;</td>
        <td valign='middle'>
          <?php if ($config_useInteraction): ?>
          <h4><a href='<?php print $product["productHREF"]; ?>'><?php print $product["name"]; ?></a> <?php if ($product["rating"]) print tapestry_stars($product["rating"],""); ?></h4>
          <?php else: ?>
          <h4><a href='<?php print $product["productHREF"]; ?>'><?php print $product["name"]; ?></a></h4>
          <?php endif; ?>
          <p><?php print substr($product["description"],0,250); ?></p>
          <?php
          $sql = "SELECT * FROM `".$config_databaseTablePrefix."reviews` WHERE product_name = '".database_safe($product["name"])."' AND approved <> '0' ORDER BY created";
          if (database_querySelect($sql,$rows))
          {
            ?>
            <table width='100%' cellpadding='4'>
              <tr bgcolor='#eeeeee'>
                <th width='100' align='left'><?php print translate("Rating"); ?></th>
                <th align='left'><?php print translate("Comments"); ?></th>
              </tr>
              <?php foreach($rows as $review): ?>
              <tr>
                <td align='center' bgcolor='#ffffcc'>
                  <?php print tapestry_stars($review["rating"],""); ?>
                </td>
                <td>
                  <?php if ($review["comments"]): ?>
                  <?php print htmlentities($review["comments"],ENT_QUOTES,$config_charset); ?>
                  <?php else: ?>
                  <em><?php print translate("This reviewer did not leave any comments."); ?></em>
                  <?php endif; ?>
                </td>
              </tr>
              <?php endforeach; ?>
            </table>
            <?php
          }
          if ($config_useRewrite)
          {
            $reviewHREF = $config_baseHREF."review/".tapestry_hyphenate($review["product_name"]).".html";
          }
          else
          {
            $reviewHREF = $config_baseHREF."reviews.php?q=".urlencode($review["product_name"]);
          }
          print "<p><a href='".$reviewHREF."'>Reviews</a></p>";
          ?>
        </td>
        <td width='50'>&nbsp;</td>
        <td valign='middle' align='center'>
          <?php if ($product["numMerchants"] > 1): ?>
            <em><?php print translate("from"); ?></em>&nbsp;<strong><?php print $config_currencyHTML.$product["minPrice"]; ?></strong><br />
            <span class='nobr'><a href='<?php print $product["productHREF"]; ?>'><?php print translate("Compare Prices"); ?></a></span>
          <?php else: ?>
            <strong><?php print $config_currencyHTML.$product["price"]; ?></strong><br />
            <span class='nobr'><a href='<?php print $product["productHREF"]; ?>'><?php print translate("More Information"); ?></a></span>
          <?php endif; ?>
        </td>
      </tr>
    <?php endforeach; ?>
  </table>
</div>
<?php
  if (file_exists("html/user_searchresults_after.php")) require("html/user_searchresults_after.php");
?>

Hope this helps!
Cheers,
David,

Submitted by scorpionwsm on Fri, 2007-07-06 12:32

Hi David,

I have found a bug in this code, where if you look at http: // www. worldhotels .org.uk /merchant /Alpha-Rooms/ all one word of course.

If you have a review of say hotel 1, then no more reviews until until 8, all the review links will goto the hotel 1 rather than to hotel 2 or hotel 3 etc, for someone to make comments regarding those hotels.

Regards

Mark

Submitted by support on Fri, 2007-07-06 13:24

Hi Mark,

Can you double check that you have this section of code copied correctly:

<?php
}
if ($config_useRewrite)
{
  $reviewHREF = $config_baseHREF."review/".tapestry_hyphenate($review["product_name"]).".html";
}
else
{
  $reviewHREF = $config_baseHREF."reviews.php?q=".urlencode($review["product_name"]);
}
print "<p><a href='".$reviewHREF."'>Reviews</a></p>";
?>

Note the position of the closing } immediately after the opening PHP tag. If this is in the wrong place, for example at the bottom of this section of code, then the $reviewHTML variable will only be updated when there are existing reviews - which sounds like what is happening on your site. If it looks OK could you email me over a copy of your modified searchresults.php and i'll take a look for you...

Cheers,
David.

Submitted by scorpionwsm on Fri, 2007-07-06 13:53

Hi David,

I re copied and pasted and works fine now, the only suggestion is that when you click on a review that is already there, it displays the hotel and description.

When you click on a review that isn't there then it takes you to a page where the hotel isn't shown e.g

http://www.book family holidays.co.uk /review/ .html (all one word)

Regards

Mark

Submitted by support on Fri, 2007-07-06 14:16

Hi Mark,

Glad that's working.

I'm not sure what you mean by a link to a page where the hotel isn't shown. The link in your last post (above) doesn't have a hotel name in the URL - which may be the problem. Can you post a link to the page that is generating the incorrect link and i'll take a look for you...

Cheers,
David.

Submitted by scorpionwsm on Fri, 2007-07-06 14:26

Hi David,

http://www.bookfamilyholidays.co.uk/search.php?q=weston+super+mare as you can see the reviews goto .html

If there is a review like I have posted a couple myself, it works fine and goes to the actual page where the hotel is.

Regards

Mark

Submitted by support on Fri, 2007-07-06 14:31

Hi Mark,

This looks like the same problem as before - have you made the same fix on this site?

The reason the top links have no hotel in the review link is because there has not yet been one with a review. If you go further down, it becomes the same problem as you described previously where each hotel with no review links to the last one that did have a review...

Cheers,
David.

Submitted by scorpionwsm on Fri, 2007-07-06 14:38

Hi David,

I just copied and pasted the code that is here at the moment. Too a degree if someone clicks on the reviews link, it should take you to the hotel and say that currently there are no product reviews, do you wish to add one kind of thing.

So if there is reviews for example, the link will say see all reviews

if there are no reviews, then the link will take you to the hotels page and allow you to post a review.

So

Reviews (for reviews)

Post a review (for no reviews)

Or either that or if there are no reviews, then the reviews link is missing.

Or something similar.

Regards

Mark

Submitted by support on Fri, 2007-07-06 16:28

Hi Mark,

What you're describing is how it should be working - if there are no reviews you go to the review page anyway and can be the first person to add one. I think there is a still an error in the control block of the code you have added to include the review link in the search results. It does look like the same problem you had before and then you fixed it on one site - but the second example link you gave was from a different site.

Feel free to email over your modified searchresults.php and i'll check it over for you.

Cheers,
David.

Submitted by scorpionwsm on Fri, 2007-07-06 16:39

Hi David,

On the works computer at the moment rather than my laptop, never know which one contains the emails, but here is the code. This was copied from the above.

<?php
  if (file_exists("html/user_searchresults_before.php")) require("html/user_searchresults_before.php");
?>
<div class='searchresults'>
  <table width='100%'>
    <?php foreach($searchresults["products"] as $product): ?>
      <tr>
        <td>
          <?php if ($product["image_url"]): ?>
          <a href='<?php print $product["productHREF"]; ?>'><img border='0' width='80' src='<?php print $product["image_url"]; ?>' alt='<?php print $product["name"]; ?>' /></a>
          <?php endif; ?>
        </td>
        <td width='50'>&nbsp;</td>
        <td valign='middle'>
          <?php if ($config_useInteraction): ?>
          <h4><a href='<?php print $product["productHREF"]; ?>'><?php print $product["name"]; ?></a> <?php if ($product["rating"]) print tapestry_stars($product["rating"],""); ?></h4>
          <?php else: ?>
          <h4><a href='<?php print $product["productHREF"]; ?>'><?php print $product["name"]; ?></a></h4>
          <?php endif; ?>
          <p><?php print substr($product["description"],0,250); ?></p>
          <?php
          $sql = "SELECT * FROM `".$config_databaseTablePrefix."reviews` WHERE product_name = '".database_safe($product["name"])."' AND approved <> '0' ORDER BY created";
          if (database_querySelect($sql,$rows))
          {
            ?>
            <table width='100%' cellpadding='4'>
              <tr bgcolor='#eeeeee'>
                <th width='100' align='left'><?php print translate("Rating"); ?></th>
                <th align='left'><?php print translate("Comments"); ?></th>
              </tr>
              <?php foreach($rows as $review): ?>
              <tr>
                <td align='center' bgcolor='#ffffcc'>
                  <?php print tapestry_stars($review["rating"],""); ?>
                </td>
                <td>
                  <?php if ($review["comments"]): ?>
                  <?php print htmlentities($review["comments"],ENT_QUOTES,$config_charset); ?>
                  <?php else: ?>
                  <em><?php print translate("This reviewer did not leave any comments."); ?></em>
                  <?php endif; ?>
                </td>
              </tr>
              <?php endforeach; ?>
            </table>
            <?php
          }
          if ($config_useRewrite)
          {
            $reviewHREF = $config_baseHREF."review/".tapestry_hyphenate($review["product_name"]).".html";
          }
          else
          {
            $reviewHREF = $config_baseHREF."reviews.php?q=".urlencode($review["product_name"]);
          }
          print "<p><a href='".$reviewHREF."'>Reviews</a></p>";
          ?>
        </td>
        <td width='50'>&nbsp;</td>
        <td valign='middle' align='center'>
          <?php if ($product["numMerchants"] > 1): ?>
            <em><?php print translate("from"); ?></em>&nbsp;<strong><?php print $config_currencyHTML.$product["minPrice"]; ?></strong><br />
            <span class='nobr'><a href='<?php print $product["productHREF"]; ?>'><?php print translate("Compare Prices"); ?></a></span>
          <?php else: ?>
            <strong><?php print $config_currencyHTML.$product["price"]; ?></strong><br />
            <span class='nobr'><a href='<?php print $product["productHREF"]; ?>'><?php print translate("More Information"); ?></a></span>
          <?php endif; ?>
        </td>
      </tr>
    <?php endforeach; ?>
  </table>
</div>
<?php
  if (file_exists("html/user_searchresults_after.php")) require("html/user_searchresults_after.php");
?>

Submitted by support on Fri, 2007-07-06 16:44

Sorry, Mark - I see the problem now.

In the above code, where you have:

          if ($config_useRewrite)
          {
            $reviewHREF = $config_baseHREF."review/".tapestry_hyphenate($review["product_name"]).".html";
          }
          else
          {
            $reviewHREF = $config_baseHREF."reviews.php?q=".urlencode($review["product_name"]);
          }

This should actually be:

          if ($config_useRewrite)
          {
            $reviewHREF = $config_baseHREF."review/".tapestry_hyphenate($product["name"]).".html";
          }
          else
          {
            $reviewHREF = $config_baseHREF."reviews.php?q=".urlencode($product["name"]);
          }

The $review["product_name"] variable was the wrong one to use at that point in the code, it should be $product["name"].

Cheers,
David.