P
P
PressOff2019-12-23 23:13:30
PHP
PressOff, 2019-12-23 23:13:30

How to configure excel upload on PHPEexcel so that mysql upload starts from the first element and not from the second?

Below code:

$link = mysqli_connect('localhost', 'root', '', 'eshop');


$query1 = mysqli_query($link, "SELECT * FROM goods");
$myrow = mysqli_fetch_array($query1);

require_once './PHPExcel/Classes/PHPExcel.php';

$phpexcel = new PHPExcel(); 
$page = $phpexcel->setActiveSheetIndex(0); 
$page->setCellValue("A1", "id"); 
$page->setCellValue("B1", "name");
$page->setCellValue("C1", "cost");
$page->setCellValue("D1", "description");   
$page->setCellValue("E1", "ord");  
$page->setCellValue("F1", "img"); 

$s = 2;
while($row = mysqli_fetch_array($query1))
{
    $s++;
    $page->setCellValue("A$s", $row['id']); 
    $page->setCellValue("B$s", $row['name']);
    $page->setCellValue("C$s", $row['cost']);
    $page->setCellValue("D$s", $row['description']);   
    $page->setCellValue("E$s", $row['ord']);  
    $page->setCellValue("F$s", $row['img']);
    
    
} 
$page->setTitle("Example"); 
$objWriter = PHPExcel_IOFactory::createWriter($phpexcel, 'Excel2007');
$objWriter->save("example.xlsx");

base on localhost:
5e011f9a66029395162801.png
what is the output in excel:
5e012082ec5da974495707.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey c0re, 2019-12-23
@PressOff

$query1 = mysqli_query($link, "SELECT * FROM goods ORDER BY id");

yes, I noticed...
why did they fetch the first line before the output in the loop??
delete it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question