02-14-2022, 01:08 PM
|
|
Confirmed User
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,143
|
Quote:
Originally Posted by ZTT
I don't know what you're trying to accomplish overall, but to group and add the figures together you could...
Process the original CSV to look like this:
Book1,001,12,340
Book2,002,10,260
Book1,001,8,240
Book5,005,2,60
And from that you'd produce a CSV like this:
Book1,001,20,580
Book2,002,10,260
Book5,005,2,60
From this:
Code:
<?php
$data = array_map('str_getcsv', file('data.csv'));
foreach($data as $datas){
$x = $datas[0];
if(isset($book[$x])){
$book[$x][2] = $book[$x][2] + $datas[2];
$book[$x][3] = $book[$x][3] + $datas[3];
}else{
$book[$x] = $datas;
}
}
$sum = fopen('sum.csv', 'w');
foreach ($book as $books) {
fputcsv($sum, $books);
}
fclose($sum);
?>
|
Thanks, I actually have the data consoiidated how I need it, I'm just having an issue displaying it by SALES $ order, when I put ORDER BY sales in the SQL query its not working (based on the query I posted above).
__________________
SOMETHING EXTREME IS COMING SOON!
|
|
|