Page 1 of 1

Help creating CSV file -php mysql-

Posted: Fri Jun 13, 2008 10:48 am
by crosero
Hello everyone,

I am having problems trying to export to a csv/excel file, I am using a excel class from phpclasses and is working fine for the first row, the only thing is that I don't know how to create a loop in the array to populate data from the recordset.

here is the original code or example:

Code: Select all

$assoc = array(
    array("Sales Person" => $name, "Q1" => "$3255", "Q2" => "$3167", "Q3" => 3245, "Q4" => 3943),
    array("Sales Person" => "Jim Brown", "Q1" => "$2580", "Q2" => "$2677", "Q3" => 3225, "Q4" => 3410),
This is my first line of the array line:

Code: Select all

$assoc = array(
 
array("Sequence Number" => $row_grids['id'], "Program CardDate" => date('Ymd', strtotime($row_grids['etime'])), "Start Time" => date('H:m', strtotime($row_grids['etime'])), "End Time" => date('H:m', strtotime($row_grids['endtime'])), "Broadcast SerialNumber" => ($row_grids['id'] * 10), "Provider" => "Esperanza TV", "Program Alt Lang" => $row_grids['series'], "Program English" => $row_grids['series'], "AltLang SubTitle" => $row_grids['series'], "English SubTitle" => $row_grids['series'], "Program" => $row_grids['program'], "Episodes" => $row_grids['programuid'], "Channel" => "Esperanza TV", "Publish Point" => "/vod/".date('Ymd', strtotime($row_grids['etime']))."/n-".$row_grids['programuid']."-".date('Ymd', strtotime($row_grids['etime'])).".asf"),
 
);
how do I loop throught the recordset?.

Thanks

Re: Help creating CSV file -php mysql-

Posted: Fri Jun 13, 2008 11:32 am
by RobertGonzalez
Where is the data coming from? What class are you using to do this?

Re: Help creating CSV file -php mysql-

Posted: Fri Jun 13, 2008 12:12 pm
by crosero
Thanks for replying,

I am pulling data from a mysql db, and I am using this class "xlsstream" from http://www.phpclasses.org/browse/package/1919.html

If you need my entire code let me know?

Thanks

Re: Help creating CSV file -php mysql-

Posted: Fri Jun 13, 2008 1:11 pm
by RobertGonzalez
Do something along the lines of:

Code: Select all

<?php
$data = array();
while ($row = mysql_fetch_assoc($result)) {
  $data[] = row;
}
?>
Then pass of the $data array to the stream writer.