Jump to content

Adding up values of numerous columns


dc_jt

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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