brianbaart
May 8th, 2009, 07:23 AM
Dear All,
I need to get a query from MySQL to a csv file.
But I need to add some data and empty variables into the csv line.
I get a file with 9 lines (which is correct) but the lines contain just the word "array"
I have following code:
<?php
include("conf.php");
$con = mysql_connect($host, $user, $password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($name, $con);
$sql = "SELECT * FROM D2D WHERE GeExporteerd = 'NEE' ORDER BY D2D_ID";
$result = mysql_query($sql);
$list = array();
while($row = mysql_fetch_array($result))
{
//it goes wrong here, I think. I need to add some variables into the array //here.
$list[] = array($row['D2D_ID'],$row['CallNummer']);
}
$file = fopen($CSV_Adres . "Contact.csv","w");
foreach ($list as $line)
{
fputcsv($file,split(',',$line));
}
fclose($file);
mysql_close($con);
?>
What did I do wrong?
I have been testing all day.
Thanks in advance,
Brian
I need to get a query from MySQL to a csv file.
But I need to add some data and empty variables into the csv line.
I get a file with 9 lines (which is correct) but the lines contain just the word "array"
I have following code:
<?php
include("conf.php");
$con = mysql_connect($host, $user, $password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($name, $con);
$sql = "SELECT * FROM D2D WHERE GeExporteerd = 'NEE' ORDER BY D2D_ID";
$result = mysql_query($sql);
$list = array();
while($row = mysql_fetch_array($result))
{
//it goes wrong here, I think. I need to add some variables into the array //here.
$list[] = array($row['D2D_ID'],$row['CallNummer']);
}
$file = fopen($CSV_Adres . "Contact.csv","w");
foreach ($list as $line)
{
fputcsv($file,split(',',$line));
}
fclose($file);
mysql_close($con);
?>
What did I do wrong?
I have been testing all day.
Thanks in advance,
Brian