php - csv file requires to open and save again in order to display data. -
i exporting csv file server , using php script fetch data csv , show on webpage.
now it's working good.
but problem have open exported csv file first , copy paste date csv file.
it not fetching data exported file straight away.
it's weird, said when copy data , provide same name csv file, same, works.
why that.
php function(although don't think there problem that)
public function import(){ $fp = fopen(data_path.'/testfile.csv', 'r'); // first (header) line $header = fgetcsv($fp); // rest of rows $data = array(); while ($row = fgetcsv($fp)) { $arr = array(); foreach ($header $i => $col) $arr[$col] = $row[$i]; $data[] = $arr; } $all = $data; $soldval=array(); foreach ($all $key=>$value){ $sold = $value["total_qty_ordered"]; array_push($soldval, $sold); } print_r($soldval); //echo '<br/>'; $totalseats = intval('1000'); $prodtotal = intval(array_sum($soldval)); $totalleft = $totalseats-$prodtotal; return 'products sold '.$prodtotal; //.' seats left '.$totalleft; }
Comments
Post a Comment