Looking at this:
Code: Select all
$sql = "SELECT id as userid, fullname, userstatus
FROM sometable
WHERE userstatus = 1";
$result = mysql_query($sql);
$fp = fopen('file.csv', 'w');
while ($row = mysql_fetch_assoc($result)) {
fputcsv($fp,$row);
}
fclose($fp);$fp - is this a way to create a temporary file called file.csv, to output the result to? Should I be expecting to see a "Save As" type box come up? Also, what is the 'w' for?
I can see the "while" area coming into play, as it's producing the results to the various in the $fp line above it.
I have done this:
Code: Select all
$sql = "SELECT id as userid, email FROM users";
$result = mysql_query($sql);
$fp = fopen('file.csv', 'w');
while ($row = mysql_fetch_object($result))
{
fputcsv($fp,$row);
}
fclose($fp);Line 18 is:Warning: fputcsv() expects parameter 2 to be array, object given in C:\xampp\phpmyadmin\site\includes\a_emailexport.inc on line 18
Warning: fputcsv() expects parameter 2 to be array, object given in C:\xampp\phpmyadmin\site\includes\a_emailexport.inc on line 18
Code: Select all
fputcsv($fp,$row);This is what I mean when I say I am flying blind. Even on reading various pages on the web about doing this apparently easy script, I am not getting terribly far from those who are trying helping.
I'm sure I am missing something rather daft here. I'm sure it's a case of extracting the data in a query, and putting it into rows on a temporary CSV, then outputting it to a file.