Reputation: 99
I want to use the 10autofilter.php from phpexcel, to our program.
But I want a code that will print on excel the datas on our database since its only prints row 1 and doesnt print all data on our mysql please help me you can see the code it only output 1 row.
I think there's a problem here but this works fine on php displaying on browser but just not in excel the output is 1 row.
I have used $i++
on $row as you can see i dont know what to do.
$res = mysql_query("select * from services");
$row = mysql_num_rows($res);
for($i=0; $i<$row; $i++)
{
$serviceid = mysql_result($res,$i,"serviceid");
$servicename = mysql_result($res,$i,"servicename");
$contactemail = mysql_result($res,$i,"contactemail");
$charge = mysql_result($res,$i,"charge");
$contactlastname = mysql_result($res,$i,"contactlastname");
$contactmiddlename = mysql_result($res,$i,"contactmiddlename");
$yearassistancereceived = mysql_result($res,$i,"yearassistancereceived");
$yearestablished = mysql_result($res,$i,"yearestablished");
$dataArray = array(
array(
$serviceid,
$servicename,
$contactemail,
$charge." ".$contactmiddlename." ".$contactlastname,
$yearassistancereceived,
$yearestablished
)
);
$objPHPExcel->getActiveSheet()->fromArray($dataArray, NULL, 'A2');
}
I also have the error:
Fatal error. Uncaught exception 'PHPExcel_WriterException' with message 'Invalid parameters passed'. why? at the bottom of the error is written C:\xampp\htdocs\DOSTPROJECT\classes\PHPExcel\Writer\Excel2007\ContentTypes.php on line 263.
This executes and excel file but I have said only 1 row data, I mean whats wrong?
Upvotes: 0
Views: 1115
Reputation: 212412
If you write every row of data to spreadsheet row #2, then the rows will all overwrite each other. You want to write the first row of data to spreadsheet row #2, the second to spreadsheet row #3, etc
You used $i++ to get each row from the database, but you're not using it when writing to PHPExcel, you're just writing every row array at cell A2
for($i=0; $i<$row; $i++)
{
$serviceid = mysql_result($res,$i,"serviceid");
$servicename = mysql_result($res,$i,"servicename");
$contactemail = mysql_result($res,$i,"contactemail");
$charge = mysql_result($res,$i,"charge");
$contactlastname = mysql_result($res,$i,"contactlastname");
$contactmiddlename = mysql_result($res,$i,"contactmiddlename");
$yearassistancereceived = mysql_result($res,$i,"yearassistancereceived");
$yearestablished = mysql_result($res,$i,"yearestablished");
$dataArray = array(
array(
$serviceid,
$servicename,
$contactemail,
$charge." ".$contactmiddlename." ".$contactlastname,
$yearassistancereceived,
$yearestablished
)
);
$objPHPExcel->getActiveSheet()->fromArray($dataArray, NULL, 'A'.($i+2));
}
Upvotes: 1