Jump to content


Photo

Echo back individual results


  • Please log in to reply
5 replies to this topic

#1 NFD

NFD
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 29 August 2006 - 06:27 PM

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:
$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";

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 :)

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 29 August 2006 - 07:19 PM

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:

echo $total_this_month;

to:

echo "<pre>" . print_r($total_this_month, true) . "</pre>";


#3 NFD

NFD
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 29 August 2006 - 07:36 PM

Ok, I will try that and see what it does.

What did you mean by "Without knowing what class you are using to interact with your database" tho?

#4 NFD

NFD
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 29 August 2006 - 07:57 PM

Did what you suggested, and it gives me:

Array
(
    [0] => Array
        (
            [total_quantity] => 
        )

)


#5 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 29 August 2006 - 08:00 PM

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.

#6 NFD

NFD
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 29 August 2006 - 08:30 PM

Does the blow tell you the class info you need?

<?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
?>

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

As for the query itself, can you see anything fundamently wrong with it ?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users