DB array within array
Posted: Wed Oct 10, 2007 3:18 pm
feyd | Please use
The problem I am running into is I need to take the totals from each id in the array as it may change and get a total. I am unable to take the totals for each id, break them out of the array created from the query and then add them together for an overall total.
Example;
id = 14629, 28070, and 28077
generate a total value for each of 413, 522, and 618 respectively.
I can get them to show up with the id information specific to each id number but when i try and get the total, which in this case should be 1553, I get no love. Any thoughts on this from anyone. Let me know if additional info is needed.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am trying to create a total from an array using information from an array retrieved via a form post but am having trouble getting the last piece to work. I have searched the forums and do not see a solution so I apologize if this is a repeat. Below is the info concerning the code. Any suggestions would be appreciated and thanks in advance.
PHP code from page capturing form post(Works great):Code: Select all
<?php
//declare variables
$id = $_POST['id'];
for ($i=0; $i<count($id); $i++){
//Create movement total
$total = MSSQL_QUERY("select sum(price_movement.quantity)
from item_price
join price_movement on item_price.item_price_id = price_movement.item_price_id
where ip_start_date >= '$startf'
and ip_end_date <= '$end'
and pt_type = '$pt'
and item_id = '$id[$i]'
");
$tq = mssql_fetch_array($total);
echo $tq[0]."<br>";
}
?>Example;
id = 14629, 28070, and 28077
generate a total value for each of 413, 522, and 618 respectively.
I can get them to show up with the id information specific to each id number but when i try and get the total, which in this case should be 1553, I get no love. Any thoughts on this from anyone. Let me know if additional info is needed.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]