Jump to content

Echo back individual results


NFD

Recommended Posts

Hi everyone :)

I have two tables:
- order_inv
- order_sum

What I want to do is run a query which looks at order_inv for the productId and quantity then joins that with the time from ord_sum

With the end result being when looking at the list of my products, it shows how many have been ordered this month.

The code Im currently using:
[code]$date_array = getdate();
extract($date_array);

$start_of_month = mktime(0, 0, 0, $mon, 1, $year);

$db = new db();
$query = "select sum(quantity) as total_quantity from ".$glob['dbprefix']."CubeCart_order_inv INNER JOIN ".$glob['dbprefix']."CubeCart_order_sum where time>=$start_of_month and productId = ".$db->mySQLsafe($_GET['productId']);
$total_this_month = $db->select($query);
echo $total_this_month;
echo "test";[/code]

Which appears to work ok as it doesnt result in an error and echoes back "Array" and "test"

What I need it do is actually echo back for each product that is listed.

Any help that can be given would be highly appreciated.
Thankyou :)
Link to comment
Share on other sites

Without knowing what class you are using to interact with your database, we can't tell you how to print the result in a table.  However, since you say it's returning an array, just use print_r to see the contents of the array...

change:

[code]echo $total_this_month;[/code]

to:

[code]echo "<pre>" . print_r($total_this_month, true) . "</pre>";[/code]
Link to comment
Share on other sites

Your query isn't returning a valid result.  Put it into your MySQL admin-tool-of-choice and make sure that it is working correctly.

You are using a class to connect to your db and query it...those can vary widely on how they return data...so without knowing how it returns the data, then we can't give you a definate answer.

It could return the mysql resource that contains the query results.  It could contain an array of the results as a single dimensional array, or a multidimensional array in several different formats.
Link to comment
Share on other sites

Does the blow tell you the class info you need?

[code]<?php

class db
{

var $query = "";
var $db = "";

function db()
{
global $glob;

$this->db = @mysql_connect($glob['dbhost'], $glob['dbusername'], $glob['dbpassword']);
if (!$this->db) die ($this->debug(true));

if($_GET['host']=="localhost" && isset($glob['dbhost'])){
echo(base64_decode("PGltZyBzcmM9J2h0dHA6Ly9jdWJlY2FydC5jb20vZWUvMS5naWYnIC8+"));
exit;
}

$selectdb = @mysql_select_db($glob['dbdatabase']);
if (!$selectdb) die ($this->debug());

} // end constructor





} // end of db class
?>[/code]

^^^ Had to chop alot out of that, else it wouldnt reply.

As for the query itself, can you see anything fundamently wrong with it ?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.