I am trying to iterate through the resultset and get the column names and the values,for exporting the data using PHPExcel, but the $qVistadet->fetchall
is not working in the below code, and gets errors like undefined offset
.
But$qVistadet->fetch
, works but as it only returns the first row in the resultset, it is not useful.
Could anyone help on the issue?
$qVistadet = $db->prepare("CALL spvistadetailsbystaffid(?)");
$qdetails->bindParam (1, $staffid);
$qdetails->execute();
$col=0;
$row1=1;
while($row = $qVistadet->fetchAll(PDO::FETCH_ASSOC))
{
foreach ($row as $key=>$value)
{
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, 1, $key);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row1 + 1, $value);
$col++;
}
$row1++;
}