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?? Link to comment https://forums.phpfreaks.com/topic/42649-adding-up-values-of-numerous-columns/ 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. Link to comment https://forums.phpfreaks.com/topic/42649-adding-up-values-of-numerous-columns/#findComment-206914 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) Link to comment https://forums.phpfreaks.com/topic/42649-adding-up-values-of-numerous-columns/#findComment-206924 Share on other sites More sharing options...
dc_jt Posted March 14, 2007 Author Share Posted March 14, 2007 Anyone? Link to comment https://forums.phpfreaks.com/topic/42649-adding-up-values-of-numerous-columns/#findComment-206944 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? Link to comment https://forums.phpfreaks.com/topic/42649-adding-up-values-of-numerous-columns/#findComment-206971 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 Link to comment https://forums.phpfreaks.com/topic/42649-adding-up-values-of-numerous-columns/#findComment-206982 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.