You are here:  » Number of all products

Support Forum



Number of all products

Submitted by Peter on Sat, 2006-07-29 16:21 in

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

Submitted by support on Sat, 2006-07-29 17:04

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.

Submitted by Peter on Sat, 2006-07-29 18:30

Thanks for your fast answer.

It works perfekt...

Peter

Submitted by bat on Sat, 2011-08-06 16:02

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

Submitted by support on Sat, 2011-08-06 16:49

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

Submitted by bat on Sat, 2011-08-06 16:58

Brill! Works like a charm. Thanks David!