NFD Posted August 29, 2006 Share Posted August 29, 2006 Hi everyone :)I have two tables:- order_inv- order_sumWhat 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_sumWith 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 :) Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 29, 2006 Share Posted August 29, 2006 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] Quote Link to comment Share on other sites More sharing options...
NFD Posted August 29, 2006 Author Share Posted August 29, 2006 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? Quote Link to comment Share on other sites More sharing options...
NFD Posted August 29, 2006 Author Share Posted August 29, 2006 Did what you suggested, and it gives me:[code]Array( [0] => Array ( [total_quantity] => ))[/code] Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 29, 2006 Share Posted August 29, 2006 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. Quote Link to comment Share on other sites More sharing options...
NFD Posted August 29, 2006 Author Share Posted August 29, 2006 Does the blow tell you the class info you need?[code]<?phpclass 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 ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.