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
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
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.
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.
The above is not working me, it shows the following
All Products
25 Beautiful Homes Magazine available for £
Next
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.
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
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.
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
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.
Hi David,
Great stuff thats working now, thanks!
Mally
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.