I have a table with up to 35 columns and up to 70 rows. My boss wants me to dump my table into an Exsmell file. Why? I don't know. Anywhoo, everything that displays on the screen needs to be copied to a .cvs file for import into Excel. Is there a way to dump the data into a .csv file via fputcsv() while the script is unfolding, or do I need to have a bunch of code at the end to write to the file?
Heavy-duty fputcsv()
fputcsv() only outputs one line at a time, so it should work fine in an incremental approach.
$fh = fopen($csvFilePathName, 'w');
while(something_or_other)
{
// get desired for data for one row into 1-D array $data, then...
fputcsv($fh, $data);
}
fclose($fh)
Took a little doing, but I figured out how to get each line into my file, BUT......
I need to take a step back. I can't get the fopen() to create my file.
$FileName = $System . ' ' . $EndMO . '.csv';
echo $FileName;
$fp = fopen($FileName, "w")
or die( 'yep, you screwed up');
$FileName is right. What am i lacking?
timstring;11023579 wrote:What am i lacking?
An error message, for starters. Do you have error_reporting set to E_ALL and display_errors (or log_errors) set to On?
I now have
display_errors = 1
error_reporting = E_ALL & ~E_DEPRECATED
log_errors = On
I am getting a monster error message:
Warning: fopen(Enid Jan-2012.csv): failed to open stream: Permission denied in /Library/WebServer/Documents/DispatchReports/callstodispatch/MonthlyReport.php on line 181
So, I took a sledgehammer and changed the permissions, and the file was created.
The big question is how am I supposed to get my data into an array so that 'fputcsv();' will write to the file? Here's what I'm dealing with:
echo '<table style = "margin:auto; border:2px solid blue; border-collapse:collapse">';
echo '<tr style="background-color:#73B0FF">';
echo '<th> Tech<br>Number:</th>';
echo '<th style="width:150px"> Name:</th>';
echo '<th />';
for ($counter=0; $counter<$NumMonth; $counter++)
{
echo '<th>' . $W["$counter"] . '<br>' . $D["$counter"] . '</th>';
}
echo '<th>Calls</th>';
echo '<th>Work<br />Orders</th>';
echo "</tr>";
Where do I go from here? Each element of the array would be between the <th> fields, and the line would terminate on the </tr>. But how would I get to an array from here?
ty
tim
[font=monospace]$W[/font] is already an array. Isn't that what you want? If not, how does it relate? How does building an HTML table from it relate to saving a CSV file?