Help creating CSV file -php mysql-

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
crosero
Forum Newbie
Posts: 2
Joined: Fri Jun 13, 2008 10:36 am

Help creating CSV file -php mysql-

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Help creating CSV file -php mysql-

Post by RobertGonzalez »

Where is the data coming from? What class are you using to do this?
crosero
Forum Newbie
Posts: 2
Joined: Fri Jun 13, 2008 10:36 am

Re: Help creating CSV file -php mysql-

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Help creating CSV file -php mysql-

Post 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.
Post Reply