calabrese Posted June 26, 2008 Share Posted June 26, 2008 Hey there, this is my first post, so hello! Now, down to business :-D I have a small script that takes information from my database and writes it to an XML file. Now - the problem I am facing is that when it writes the database information to the file, it is all the same. Here is my code... if(isset($_GET['download'])) { include 'xls.php'; $getusers = mysql_query("SELECT * FROM `members` ORDER BY `id` ASC") or die(mysql_error()); $xls = new XLS(); while ($user = mysql_fetch_array($getusers)) { for ($counter = 0; $counter <= mysql_fetch_array($getusers); $counter+=1){ $xls->add_cell(0,$counter,$user['username']); $xls->add_cell(1,$counter,$user['email']); $xls->add_cell(2,$counter,$user['location']); } } $xls->save_file('download.xls'); echo "<a href='download.xls'>Right Click > Save As</a>"; } It has to be something small, but I am just missing it. Any help would be greatly appreciated! Link to comment https://forums.phpfreaks.com/topic/111962-solved-question-regarding-for-loop/ Share on other sites More sharing options...
fanfavorite Posted June 26, 2008 Share Posted June 26, 2008 You don't need the for loop. The while loop goes through everything in the database and the for loop was just displaying the same records over and over because it is still on row 1 of the while loop. if(isset($_GET['download'])) { include 'xls.php'; $getusers = mysql_query("SELECT * FROM `members` ORDER BY `id` ASC") or die(mysql_error()); $xls = new XLS(); while ($user = mysql_fetch_array($getusers)) { $xls->add_cell(0,$counter,$user['username']); $xls->add_cell(1,$counter,$user['email']); $xls->add_cell(2,$counter,$user['location']); } $xls->save_file('download.xls'); echo "<a href='download.xls'>Right Click > Save As</a>"; } Link to comment https://forums.phpfreaks.com/topic/111962-solved-question-regarding-for-loop/#findComment-574682 Share on other sites More sharing options...
calabrese Posted June 26, 2008 Author Share Posted June 26, 2008 You sir have saved me a lot of trouble! Thank you. Link to comment https://forums.phpfreaks.com/topic/111962-solved-question-regarding-for-loop/#findComment-574685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.