|
Posted by Pedro Graca on 11/20/06 21:17
Auddog wrote:
> Here is approximately what I'm wanting to get:
>
> Item Number: 39990
>
> - 10704-02 65321 55.60
> - 10704-02 65322 55.60
> - 10704-02 65322 55.60
>
> Item Count: 3
> Grand Total: 166.80
>
>
> I'm unable to get the count and grand total of onto my page. Here is the
> code that I'm currently working with:
<snip>
> Is there a way that I can do the count and add together the prices of each
> item numbers? If so where do I place the code for the count and how would I
> get the sum?
You can count and sum in the database, but, seeing you're already
fetching the individual rows, I'd do it with PHP (and avoid another SQL
query).
To use the database for count and sum, you'd have to execute another
query:
select count(*), sum(price) from production where item_no='$item_no'
But you already have a query that fetches them all and prints them in a
loop. So i'd use that to calculate the $count and $total.
// ...
$count = 0;
$total_price = 0;
while (list($id, $order_no, $serial_no, $price) = @mysqli_fetch_row($result2)) {
echo "<li>$order_no $serial_no $price";
++$count;
$total_price += $price;
}
# echo "<p>";
echo "</ul>";
echo "Item Count: $count<br>\n";
echo "Grand Total: " . number_format($total_price, 2) . "<br>\n";
// ...
--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
[Back to original message]
|