Help with PHPExcel Library and mySQL data from a table

五迷三道 提交于 2019-12-11 00:37:00

问题


I have this script

$query = "SELECT id,last_name,first_name FROM users WHERE tmima_id='6'";
$result = @mysql_query($query); 

while($row = mysql_fetch_array($result))
{
    $i = 3;

    $emp_id = $row['id'];

    $cell = 'A'.$i;

    $objPHPExcel->setActiveSheetIndex(0)
       ->setCellValue($cell, $row['last_name']. $row['first_name']);
    $i++;
}

But in the .xls file it prints only one user. Why id doesnt print all of the users ? W

Thanks in advance.


I make the change you said with $sheet

$query = "SELECT id,last_name,first_name FROM users WHERE tmima_id='6'";
 $result = @mysql_query($query);

 while($row = mysql_fetch_array($result))
 {
  $i = 3;

   $emp_id = $row['id'];

   $cell = 'A'.$i;


   $sheet->setCellValue($cell, $row['last_name']. $row['first_name']);


   $i++;
 }

But it still prints out only one record. And yes when i run the query in phpmyadmin it returns more than one record.

How can i print out data from mySql table.. What is going wrong ?


回答1:


I am pretty sure it is because you are using a unique identifier (WHERE tmima_id='6'). It is only finding the results for that one unique identifier and displaying that. Hope this helps.




回答2:


$i is being reset to row 3 every loop. Set $i=3; before the while loop, not inside it.



来源:https://stackoverflow.com/questions/4480963/help-with-phpexcel-library-and-mysql-data-from-a-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!