Results 1 to 6 of 6
  1. #1

    Default 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 Code:
    <?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.
    My most recent work: magprom.net

  2. #2
    Join Date
    Dec 2009
    Location
    Amersfoort, The Netherlands
    Posts
    2,845
    Plugin Contributions
    25

    Default Re: All products value total need help

    mysql_query is depricated.

    It is better to use the build in sql queries.

    like below.
    PHP Code:
     <?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>'
          
    ?>

  3. #3

    Default 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 .

    Thank you for your help.
    My most recent work: magprom.net

  4. #4

    Default 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.
    My most recent work: magprom.net

  5. #5
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: All products value total need help

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

    Try something like:

    Code:
     <?php
    global $db; 
    $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>'; 
          ?>
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  6. #6
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: All products value total need help

    Quote Originally Posted by Ajeh View Post
    To use the $db things you need to have a:
    global $db;

    Try something like:

    Code:
     <?php
    global $db; 
    $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>'; 
          ?>
    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.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. v151 Need help deleting all products!
    By discountvapor.net in forum Installing on a Linux/Unix Server
    Replies: 1
    Last Post: 25 Feb 2014, 04:46 AM
  2. Need Help with All Products Layout
    By Dagoon in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 18 Oct 2009, 09:01 PM
  3. Need cart total value only. No currency sign.
    By strelitzia in forum Contribution-Writing Guidelines
    Replies: 5
    Last Post: 1 Oct 2008, 02:42 PM
  4. Total value of all listed items?
    By kpax in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 29 Aug 2007, 11:22 AM
  5. Adding products as a %age of total order with minimum value
    By gaekwad in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 9 Jul 2007, 10:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg