php - PHPExcel loop through rows and columns -
need identifying weird problem i'm facing. did tried searching in stack overflow didn't find possible answer.
here sample program works displaying rows , columns on ui
<?php date_default_timezone_set('america/los_angeles'); require_once 'phpexcel-1.8/classes/phpexcel.php'; include 'phpexcel-1.8/classes/phpexcel/iofactory.php'; $path = 'demo.xlsx'; $sheet = $objphpexcel->getsheet(0); $highestrow = $sheet->gethighestrow(); $highestcolumn = $sheet->gethighestcolumn(); $highestcolumnindex = phpexcel_cell::columnindexfromstring($highestcolumn); ($row = 2; $row <= $highestrow; ++ $row) { $val=array(); ($col = 0; $col < $highestcolumnindex; ++ $col) { $cell = $worksheet->getcellbycolumnandrow($col, $row); $val[] = $cell->getvalue(); //end of loop } $col1 = $val[0] ; $col2 = $val[1] ; $col3 = $val[2]; echo $col1; echo $col2; echo $col3; echo "<br>"; //end of loop } ?>
this program works fine printing columns , rows n-lenght
problem - our requirement values of col1, col2, col3 , using mysql_query compare database , further action.
minute add above //end of loop. iterates once , stops without throwing php errors.
e.g.
.....
echo $col1; echo $col2; echo $col3; echo "<br>"; **$sql = mysql_query("select coalesce(max(srno), 0) max_no tablea columna = 1 , columnb = '$col3'"); $row = mysql_fetch_array($sql); echo $row["max_no"];** //end of loop } ?>
if add above sql same program iterates once , stops? doesn't show errors in logs or on screen.
thanks in advance help!.
as you're using same variable $row
row number in excel iteration , result of select query, it's not surprising you're running problems.....
the integer value holds excel row number being overwritten array sql query, , you're trying use result array next excel row number
solution: use different variable these 2 elements.
$rowdata = mysql_fetch_array($sql); echo $rowdata["max_no"];**
Comments
Post a Comment