dc_jt Posted March 14, 2007 Share Posted March 14, 2007 Hi I have a product table containing: product_id product price I then have data such as product_id = 1 product = test price = 10 product_id = 2 product = test2 price = 20 product_id = 3 product = test3 price = 30 Then I have a survey results table with the following: survey_results_id surveyor_id survey_date job_id room_id location_id elevation_id date_posted So job_id 123 had each product, how would i add these up. I would have to select all products from product table and relate this to the product_id in the survey results table?? Quote Link to comment Share on other sites More sharing options...
Vikas Jayna Posted March 14, 2007 Share Posted March 14, 2007 In which table is the relation between job_id and product_id defined? Its not there in the above two tables. Quote Link to comment Share on other sites More sharing options...
dc_jt Posted March 14, 2007 Author Share Posted March 14, 2007 Sorry I have product_id in the 2nd table also (the survey_results table) Quote Link to comment Share on other sites More sharing options...
dc_jt Posted March 14, 2007 Author Share Posted March 14, 2007 Anyone? Quote Link to comment Share on other sites More sharing options...
Barand Posted March 14, 2007 Share Posted March 14, 2007 What do you want to add, a count of the number of products or the total price of those products for each job? Quote Link to comment Share on other sites More sharing options...
dc_jt Posted March 14, 2007 Author Share Posted March 14, 2007 Sorry didnt really make myself clear I wanted to add the total of the type of each product depending on the job_id I done it using this anyway if anyone would like to know: public function GetStorageTotal($iJobsId) { $sSql = "SELECT sum(p.load) AS storage_load from survey_results sr INNER JOIN product p ON p.product_id = sr.product_id WHERE p.type ='storage' && sr.job_id = '$iJobsId'"; $load = mysql_fetch_object(mysql_query($sSql, $db)); return $load->storage_load; } Thanks anyway 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.