I'm currently working with the script http://www.phpsimple.net/tutorials/mysql_to_excel/. My problem is that I have a constantly changing table that adds columns. The script he has can be used for a set amount of columns that don't change. I've changed the code around a bit but can't seem to figure out the logic needed.
This code goes through and creates the labels for all the column headings as needed.
$result = mysql_query("select * from `Athlete` order by `AthleteID` asc");
$fields = array();
for ($i = 0; $i < mysql_num_fields($result); $i++) {
$fields[] = mysql_field_name($result, $i);
}
$i=0;
foreach($fields as $field){
xlsWriteLabel(0,$i,$field);
$i++;
}
It then goes through all of the data and creates all the labels it needs. (Im a beginner with working with for statements and the like so this could probably be coded better, any suggestions appreciated!)
$c=0;
$l=0;
while($row=mysql_fetch_array($result)){
for ($n = 0; $n < 1; $n++) {
$l++;
$c=0;
foreach($fields as $field){
$label = '"'.$row[$field].'"';
xlsWriteLabel($l,$c,$label);
$c++;
}
}
}
Where I think the problem lies is where the code has all the headers. I believe at that point when the document calls the headers, the data hasn't processed yet. How to I keep it from creating the .xls until after all of the code is parsed?
Thanks in advance,
Scott