Page 1 of 1

Summing prices

Posted: Wed Sep 19, 2007 5:34 am
by shivam0101
I have a invoice table,

invoice

Invoice_Id
User_Id
Products
Amount
Qty

I have to display like,

Products Qty Price Total
pd1 1 100 100
pd2 2 100 200

Code: Select all

$i=0;
	foreach($invids as $invid)
	{
	   $i++;
	   $query_product_details=mysql_query("SELECT * FROM invoice WHERE Invoice_Id=$invid");
	   while($fetch_details=mysql_fetch_array($query_product_details))
	   {
	                                $products=$fetch_details['Services'];  $quantity=$fetch_details['Qty'];
			$price=$fetch_details['Amount'];       $total=$fetch_details[''];
			
	   		$content.="<tr><td>$i</td> <td>$products</td> <td>$quantity</td> <td>$price</td></tr>";
       }	
	}
Item_No is foreign key

But, i am not getting

Posted: Wed Sep 19, 2007 7:33 am
by Hemlata
Hello shivam0101,

Modify your code with the following

Code: Select all

$i=0;
        foreach($invids as $invid)
        {
           $i++;
           $query_product_details=mysql_query("SELECT * FROM invoice WHERE Invoice_Id=$invid");
           $total = 0;
           while($fetch_details=mysql_fetch_array($query_product_details))
           {
                                        $products=$fetch_details['Services'];  $quantity=$fetch_details['Qty'];
                        $price=$fetch_details['Amount'];       $total+=$fetch_details['Amount'];
                       
                     $content.="<tr><td>$i</td> <td>$products</td> <td>$quantity</td> <td>$price</td><td>$total</td></tr>";
       }       
        }
I think this should solve your problem .

Regards