Hello,
how can i display the number off all products in my database?
I did make it with following code, but it did not work...
$sql = "Select count(*) from products";
$result = mysql_query($sql);
$rec = mysql_fetch_row($result);
Please help me :)
Thanks a lot, Peter
I want to use this on the index page, but how would I go about it? I'm using the latest version. I've tried the require command but that didn't work...
Thanks
Hello bat,
The problem you're having is most likely because of duplicate includes (the above code is for use on a non-Price Tapestry PHP page).
To include the product count in your index.php, insert the following at the point required;
$sql = "SELECT count(*) as numProducts FROM `".$config_databaseTablePrefix."products`";
database_querySelect($sql,$rows);
$numProducts = $rows[0]["numProducts"];
print "<p>Total products in database: ".$numProducts."</p>";
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Hi Peter,
Using the database library in the Price Tapestry distribution, here's a script to show you the total number of products (put this script in your Price Tapestry directory):
numProducts.php:
<?php
require("config.php");
require("includes/database.php");
$sql = "SELECT count(*) as numProducts FROM `".$config_databaseTablePrefix."products`";
database_querySelect($sql,$rows);
$numProducts = $rows[0]["numProducts"];
print "<p>Total products in database: ".$numProducts."</p>";
?>
Your code is not far off - I think you would have just need to print the value of $rec["count(*)"] to get the product count.
Cheers!
David.