开发者

Help with PHPExcel Library and mySQL data from a table

I have this script

$query = "SELECT id,last_name,first_name FROM users WHERE tmima_id='6'";
$result = 开发者_如何学Python@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 ?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜