I have an array whose structure is like $data = array{0=>'abc',1=>xyz,2=>tqs}
Now I need to write these values into a csv file. I need to display every value in 1st column and with everytime new row on new insert along with previous value already available.
Below is the code I am using but everytime I execute it I get the last value in the file:
for ($c=0; $c < $num; $c++) {
echo $data[$c];
echo $query = "select prod_sku,prod_name
from
tbl_product
where
prod_sku = '".$data[$c]."'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
if(empty($row)){
print_r($row);
echo 'test';
$fp = fopen("file.csv", "w");
print_r($data[0]);
fputcsv($fp, $data[0]);
fclose($fp);
}
How can i achieve this using PHP?