Data from mySQL database problem

Topics: Developer Forum
Dec 19, 2010 at 6:34 PM


Hi guys


I have this code and although when i run the query in phpmyadmin it returns 3 records, in Excel file it returns only one. How can i print out these data?


$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']);


Thanks in advance!
Dec 19, 2010 at 9:07 PM



You initialise $i inside your while loop, thus overwritting the same cell each iteration. ie. move the $i=3; to before the while declaration.

As a side note I would like to say that I personally find the use of the @ operator extremely evil, it is much better to use a decent error handler.




Dec 19, 2010 at 9:23 PM

Oh thanks a lot dude! That really worked!