nerd99 Posted August 16, 2010 Share Posted August 16, 2010 For the section of code below, is there a way to say, "first time through the query print on A2, B2,etc, then each query following add increase the number besides column name to be A3, B3, etc, then A4, B4, etc"...? $result = mysqli_query($connection,"SELECT * FROM table") or die(mysqli_error($connection)); while($row = mysqli_fetch_array($result)) { //get all rows you want from the table $var1 = $row['var1']; $var2 = $row['var2']; $var3 = $row['var3']; $var4 = $row['var4']; $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A2', $var1) ->setCellValue('B2', $var2) ->setCellValue('C2', $var3) ->setCellValue('D2', $var4); } This is for an excel spreadsheet. The code is currently printing/exporting one row only from the table. Thanks Link to comment https://forums.phpfreaks.com/topic/210901-how-to-loop-and-increase-column-number/ Share on other sites More sharing options...
btherl Posted August 16, 2010 Share Posted August 16, 2010 Does this do what you want? $result = mysqli_query($connection,"SELECT * FROM table") or die(mysqli_error($connection)); $index = 2; while($row = mysqli_fetch_array($result)) { //get all rows you want from the table $var1 = $row['var1']; $var2 = $row['var2']; $var3 = $row['var3']; $var4 = $row['var4']; $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A' . $index, $var1) ->setCellValue('B' . $index, $var2) ->setCellValue('C' . $index, $var3) ->setCellValue('D' . $index, $var4); $index++; } Link to comment https://forums.phpfreaks.com/topic/210901-how-to-loop-and-increase-column-number/#findComment-1100020 Share on other sites More sharing options...
nerd99 Posted August 17, 2010 Author Share Posted August 17, 2010 Wow, thanks a bunch btherl! So simple. Link to comment https://forums.phpfreaks.com/topic/210901-how-to-loop-and-increase-column-number/#findComment-1100190 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.