Hi folks.
Im running a script that creates a session csv file populated with 4 variable elements per line...
var[1],var[2],var[3],var[4]
var[1],var[2],var[3],var[4]
and so-on...
the number of lines can be from 1 to whatever, but will always have 4 vars per line
now the question is how can i get the sum of all instances of var[3] (always a number)
i could get the total if all var[3]'s were passed into another array.
but I can't seem to find the way of passing the vars.
heres a chunk of the code that extracts all of the data from the csv array...
if ($action=="submit") {
$ordre_id = (substr(uniqid (""), 2, 7));
$fp = fopen ("./sessions/".$sessionid.".dat", "r");
$row = 1;
while ($data = fgetcsv ($fp, 500)) {
$new_data[$row] = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n".$data[0]." ".$data[1]."\n".$data[3]." x ".$data[2]." = ".number_format(($data[2] * $data[3]),2);
$row++;
if (! empty($no_prod) ) {
$no_prod = $no_prod + $data[3];
}
$tot_pos = number_format($tot_pos + ($data[2] * $data[3]),2);
}
I just cant figure how to get the secondary data I need.
its a shopping cart type script, and what I need is to get the number total of the values of $data[3] (qty for each line item in the order) so I can calculate shipping costs based on number of items (this is why I can't simply count rows).
any suggestions?