Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
-
shivam0101
- Forum Contributor
- Posts: 197
- Joined: Sat Jun 09, 2007 12:09 am
Post
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
-
Hemlata
- Forum Commoner
- Posts: 35
- Joined: Mon Sep 10, 2007 5:40 am
- Location: India
-
Contact:
Post
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