Hi All,
I am trying to create a csv file that can be sent as a datafeed to a website on behalf of my client. The data written to the csv file comes from the clients database (MySQL) and I am using the following script.
$handle = fopen("dstock.csv","w"); //local file
$sql = "select regnum, manu, model, spec, year, regnum, colour, blank, miles, price, gears, blank, fuel, doors, cc, regnum, blank, extra from stock";
$result = mysql_query($sql);
$count = mysql_num_fields($result);
while ($rows = mysql_fetch_array($result))
{
fwrite($handle,'"","",');
for ($i=0;$i<$count;$i++){
fwrite($handle, '"'.$rows[$i].'",'); //data
}
fwrite($handle,("\n")); //new line
}
fclose($handle);
That bit works fine, however, I need to amend some of the data in the CSV and I am not sure how to do it. Basically the field for 'gears' may have a character 'a', which in the CSV needs to read 'Automatic'.
There are several fields that need amending and I wondered if anyone could point me in the right direction.
I am currently considering writing the csv file back into a different table and changing it as I write it back.
Is that the best way? Any suggestions would be most welcome.
Thanks