You are here:  » Showing all items

Support Forum



Showing all items

Submitted by TomasLepp on Sat, 2007-12-08 20:31 in

Hi David,

About the code in http://www.pricetapestry.com/node/965

is there a way to just show products, one by one, instead of get all listed.

Regards, Tom

Submitted by support on Sat, 2007-12-08 21:33

Hi Tom,

The following modification should show products one by one with a link to next & previous...

<?php
  
require("includes/common.php");
  require(
"html/header.php");
  require(
"html/menu.php");
  require(
"html/searchform.php");
  
$banner["h2"] = "<strong>".translate("All Products")."</strong>";
  require(
"html/banner.php");
  if (!
$_GET["start"]) $start 1;else $start intval($_GET["start"]);
  
$sql "SELECT name FROM ".$config_databaseTablePrefix."products ORDER BY name LIMIT ".$start.",1";
  if (
database_querySelect($sql,$rows))
  {
    foreach(
$rows as $product)
    {
      if (
$config_useRewrite)
      {
        
$href $config_baseHREF."product/".tapestry_hyphenate($product["name"]).".html";
      }
      else
      {
        
$href $config_baseHREF."products.php?q=".urlencode($product["name"]);
      }
      print 
"<p><a href='".$href."'>".$product["name"]."</a></p>";
    }
  }
  print 
"<p>";
  if (
$start 1)
  {
    print 
"<a href='?start=".($start-1)."'>Previous</a> ";
  }
  print 
"<a href='?start=".($start+1)."'>Next</a> ";
  print 
"</p>";
  require(
"html/footer.php");
?>

Cheers,
David.

Submitted by TomasLepp on Sat, 2007-12-08 23:36

Hi David,

Thanks for the fast respons.

I may was little wage in my post, sorry about that.
What i meant was to show the items, kinda like this:

Product item 1
Product item 2
Product item 3
Product item 4
Product item 5

Not like:

Product item 1
Product item 1
Product item 1
Product item 2
Product item 2

If you understand what i mean, becourse the same product shows up several times on the list.

Great script by the way.

Tom

Submitted by support on Sun, 2007-12-09 09:36

Hi Tom,

Sorry - no problem. All you need to is change the SQL in the original version from:

  $sql = "SELECT name FROM ".$config_databaseTablePrefix."products ORDER BY name";

to:

  $sql = "SELECT DISTINCT(name) FROM ".$config_databaseTablePrefix."products ORDER BY name";

That should do the trick!
Cheers,
David.

Submitted by TomasLepp on Sun, 2007-12-09 09:43

Thanks David,

That fixed it :)

Cheers,
Tomas

Submitted by mally on Sat, 2007-12-22 18:31

Hello David.

Submitted by support on Sat, 2007-12-22 19:08

Hi Mal,

Should be - have a go with this:

<?php
  
require("includes/common.php");
  require(
"html/header.php");
  require(
"html/menu.php");
  require(
"html/searchform.php");
  
$banner["h2"] = "<strong>".translate("All Products")."</strong>";
  require(
"html/banner.php");
  if (!
$_GET["start"]) $start 1;else $start intval($_GET["start"]);
  
$sql "SELECT name,MIN(price) as minPrice,MAX(price) as maxPrice FROM ".$config_databaseTablePrefix."products GROUP BY name ORDER BY name LIMIT ".$start.",10";
  if (
database_querySelect($sql,$rows))
  {
    foreach(
$rows as $product)
    {
      if (
$config_useRewrite)
      {
        
$href $config_baseHREF."product/".tapestry_hyphenate($product["name"]).".html";
      }
      else
      {
        
$href $config_baseHREF."products.php?q=".urlencode($product["name"]);
      }
      print 
"<p>";
      print 
"<a href='".$href."'>".$product["name"]."</a> ";
      if (
$record["maxPrice"] > $record["minPrice"])
      {
        print 
"available from ".$config_currencyHTML.$product["minPrice"]." to ".$config_currencyHTML.$product["maxPrice"];
      }
      else
      {
        print 
"available for ".$config_currencyHTML.$product["minPrice"];
      }
      print 
"</p>";
    }
  }
  print 
"<p>";
  if (
$start 1)
  {
    print 
"<a href='?start=".($start-1)."'>Previous</a> ";
  }
  print 
"<a href='?start=".($start+1)."'>Next</a> ";
  print 
"</p>";
  require(
"html/footer.php");
?>

Cheers,
David.

Submitted by mally on Sat, 2007-12-22 20:46

The above is not working me, it shows the following

All Products
25 Beautiful Homes Magazine available for £

Next

Submitted by support on Sat, 2007-12-22 20:50

Ooops -

The variables such as $minPrice should actually be $product["minPrice"] etc.

I've corrected this in the code above; however it looks like there may still be an issue with the grouping causing the paging to not work properly - let me know if that's the case...

Cheers,
David.

Submitted by mally on Sat, 2007-12-22 20:59

hello David

It is showing the from price now but not the from and to price when there is different prices available.

Also is it possible to show the whole list of products?

thanks

Submitted by support on Sat, 2007-12-22 21:05

Hi Mal,

Sorry about this - there was another place in the code where I had $minPrice instead of $record["minPrice"]... I've fixed it in the code above (it's the place where the IF statement is to decide which text to show).

Regarding the whole list of products, I hadn't spotted that there was a "LIMIT 1" in the code above. I've changed this to 10 which will forward / next through the whole list in blocks of 10. This is achived by the following section of code on the end of the line that constructs the SQL:

LIMIT ".$start.",10

If you want to remove the limit and display all products, simply remove that code (make sure the SQL is terminated with a "). You might also want to remove the Next / Prev links if you do that of course...!

Cheers,
David.

Submitted by mally on Sat, 2007-12-22 22:24

Hello David

I'm still having problems.

I copied the above code and to out the limit.

Theres still no range of prices shown, only the cheapest

demo at Magazine Subscriptions

Mally

Submitted by support on Sun, 2007-12-23 08:08

Hi Mal,

Sorry about this.... This line:

if ($record["maxPrice"] > $record["minPrice"])

...should be:

if ($product["maxPrice"] > $product["minPrice"])

That should be more like it...

Cheers,
David.

Submitted by mally on Sun, 2007-12-23 08:42

Hi David,

Great stuff thats working now, thanks!

Mally