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
https://forums.phpfreaks.com/topic/19048-echo-back-individual-results/
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]
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.
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 ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.