You are here:  » Random Products

Support Forum



Random Products

Submitted by cq on Tue, 2007-09-04 06:35 in

Hi David,

I have inserted the code below to index.php. It works fine. But how can I fixed the same width and height of the all the products to be display.

Also the code below pick the products at random from the merchant. How if i want to

1. have let say 10 products from this merchant to be randomly display.

2. have can i fixed the products that i want to display from this merchant instead of randomly.

thanks

jack

print "<table width='728' border='0' cellspacing='5' cellpadding='0'>";
  print "<tr width='190'>";
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE merchant='Perfume' ORDER BY RAND() LIMIT 4";
  database_querySelect($sql,$products);
  foreach($products as $product)
  {
  if ($product["image_url"])
  {
    $productHREF = $config_baseHREF."product/".str_replace(" ","-",$product["name"]).".html";
    print "<td align='center'>";
    print "<a href='".$productHREF."' ><img width='100' height='100' border=0 src='".$product["image_url"]."' alt='".$product["name"] ."' /></a><br>";
    print "<font size=2> <a href='".$productHREF."'> ".$product["name"]."</a><br>";
//print $config_currencyHTML.$product["price"]." <br /></font>\n";
?>
<small><br>
            <?php if ($product["reviews"]): ?>
      <?php print tapestry_stars($product["rating"],"s"); ?>&nbsp;
              <a href='<?php print "review/".tapestry_hyphenate($product["name"]).".html"?>'><?php print $product["reviews"]." ".translate("Reviews"); ?></a>
            <?php else: ?>
              <a href='<?php print "review/".tapestry_hyphenate($product["name"]).".html"?>'><?php print translate("Review This Product"); ?></a>
            <?php endif; ?>
            </small><br>
<?php
    print "</td>";
  }
  else
  {
    print "<td>&nbsp;</td>";
  }
}
print "</tr>";
print "</table>";

Submitted by support on Tue, 2007-09-04 08:28

Hello Jack,

To make the items the same width and height I would have suggested fixing the image dimensions which I notice you have done. However this may be causing distortion, so what is sometimes better to do (and is what the search results HTML module does) is to just fix the width. This allows the browser to resize the image to scale and would normally look better.

To change the SQL to return 10 random products, simply change "LIMIT 4" to "LIMIT 10" on the line that constructs the SQL statement. To pick fixed products, change the line that constructs the SQL statement as follows:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name IN ('Product 1','Product 2','Product 3') AND merchant='Perfume'";

...Simply change Product 1, Product 2 etc. etc. (and add more products to the list, separated by commas) to get the products you want.

Hope this helps!
Cheers,
David.

Submitted by cq on Tue, 2007-09-04 10:10

thanks david

Submitted by cq on Tue, 2007-09-04 14:13

Hi David,

I change to the script below but it did not work. Nothing being display on the browser.

print "<table width='728' border='0' cellspacing='5' cellpadding='0'>";
  print "<tr width='190'>";
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name IN ('SK-II-by-SK-II-SK-II-Facial-Treatment-Repair-C-1-oz-for-WOMEN','KENZO-DETE-by-Kenzo-EDT-SPRAY-25-oz-for-WOMEN','RAMPAGE-BUTTERFLY-by-Rampage-EDP-SPRAY-17-oz-for-WOMEN','Benetton-United-by-Benetton-EDT-Spray-34-oz-for-WOMEN') AND merchant='Perfume'";
  database_querySelect($sql,$products);
  foreach($products as $product)
   {
  if ($product["image_url"])
  {
    $productHREF = $config_baseHREF."product/".str_replace(" ","-",$product["name"]).".html";
    print "<td align='center'>";
    print "<a href='".$productHREF."' ><img width='100' height='100' border=0 src='".$product["image_url"]."' alt='".$product["name"] ."' /></a><br>";
    print "<font size=2> <a href='".$productHREF."'> ".$product["name"]."</a><br>";
//print $config_currencyHTML.$product["price"]." <br /></font>\n";
?>
<small><br>
            <?php if ($product["reviews"]): ?>
      <?php print tapestry_stars($product["rating"],"s"); ?>&nbsp;
              <a href='<?php print "review/".tapestry_hyphenate($product["name"]).".html"?>'><?php print $product["reviews"]." ".translate("Reviews"); ?></a>
            <?php else: ?>
              <a href='<?php print "review/".tapestry_hyphenate($product["name"]).".html"?>'><?php print translate("Review This Product"); ?></a>
            <?php endif; ?>
            </small><br>
<?php
    print "</td>";
  }
  else
  {
    print "<td>&nbsp;</td>";
  }
}
print "</tr>";
print "</table>";

Submitted by support on Tue, 2007-09-04 14:18

Hi,

You don't need to use the "-" to separate the words in the product names as the products are in the database with spaces as normal.

That should be all it is!
Cheers,
David.