Zen Cart Logo
Forums / General Questions / All products value total need help

All products value total need help

Views: 576

Results 1 to 6 of 6
13 Apr 2015, 3:51 PM
#1
perfumbg avatar

perfumbg

Zen Follower

Join Date:
May 2010
Posts:
192
Plugin Contributions:
5

All products value total need help

Hello,
I have writen a short code that gives me an idea of how much goods i have in stock.
here is the code i used with zen cart v1.5.1

<?php
 
	  $all_products_sumquery_raw = mysql_query("
SELECT SUM(products_quantity * products_price_sorter) AS grand_total
FROM products
WHERE products_quantity > '0'
");
$test1 = mysql_fetch_array($all_products_sumquery_raw);
echo '<h2>Total value: <span class="totalUred">'.number_format($test1[0], 2, ',', ' ').'</span>$.</h2>';
	  ?>

Sinse i moved to 1.5.4 and coppied the code to admin/index.php the result is 0,00 (no value returned)

Does somebody knows what change must be done?

Best regards.

13 Apr 2015, 4:06 PM
#2
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: All products value total need help

mysql_query is depricated.

It is better to use the build in sql queries.

like below.

 <?php 
$all_products_sumquery_raw = "SELECT SUM(products_quantity * products_price_sorter) AS grand_total 
                                           FROM ' . TABLE_PRODUCTS . '
                                           WHERE products_quantity > '0'"; 
$test1 = $db->Execute($all_products_sumquery_raw); 
echo '<h2>Total value: <span class="totalUred">'.number_format($test1[0], 2, ',', ' ').'</span>$.</h2>'; 
      ?>  

13 Apr 2015, 4:19 PM
#3
perfumbg avatar

perfumbg

Zen Follower

Join Date:
May 2010
Posts:
192
Plugin Contributions:
5

Re: All products value total need help

I tested your code but is returning an error.
Just found that mysql_fetch_array is depricated too :smile:.

Thank you for your help.

16 Apr 2015, 6:52 AM
#4
perfumbg avatar

perfumbg

Zen Follower

Join Date:
May 2010
Posts:
192
Plugin Contributions:
5

Re: All products value total need help

I couldnt solve it by myself. I cant figure out where is the problem, no mater what i do i cant return any results even for the total products avaliable.

Any help is appreciated.

16 Apr 2015, 12:48 PM
#5
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: All products value total need help

To use the $db things you need to have a:
global $db;

Try something like:

 <?php
[B]global $db; [/B]
$all_products_sumquery_raw = "SELECT SUM(products_quantity * products_price_sorter) AS grand_total 
                                           FROM ' . TABLE_PRODUCTS . '
                                           WHERE products_quantity > '0'"; 
$test1 = $db->Execute($all_products_sumquery_raw); 
echo '<h2>Total value: <span class="totalUred">'.number_format($test1[0], 2, ',', ' ').'</span>$.</h2>'; 
      ?>
16 Apr 2015, 1:03 PM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: All products value total need help

Ajeh:

To use the $db things you need to have a:
global $db;

Try something like:

<?php [B]global $db; [/B] $all_products_sumquery_raw = "SELECT SUM(products_quantity * products_price_sorter) AS grand_total FROM [B]"[/B] . TABLE_PRODUCTS . [B]"[/B] WHERE products_quantity > '0'"; $test1 = $db->Execute($all_products_sumquery_raw); echo '<h2>Total value: <span class="totalUred">'.number_format($test1[0], 2, ',', ' ').'</span>$.</h2>'; ?>

Quotes are/were also incorrect around TABLE_PRODUCTS... See above.

To possibly also see what is wrong as reported by ZC, check your logs directory for myDebug files.