title: PHPExcel loop through rows and columns
body: <p>Need help identifying weird problem that i'm facing. I did tried searching in stack overflow but didn't find any possible answer. </p>
  
  <p>Here is sample program that works displaying all rows and columns on UI</p>
  
  <pre><code>&lt;?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-&gt;getSheet(0);
  $highestRow = $sheet-&gt;getHighestRow();
  $highestColumn = $sheet-&gt;getHighestColumn();
   $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
  for ($row = 2; $row &lt;= $highestRow; ++ $row) {
      $val=array();
  for ($col = 0; $col &lt; $highestColumnIndex; ++ $col) {
     $cell = $worksheet-&gt;getCellByColumnAndRow($col, $row);
     $val[] = $cell-&gt;getValue();
   //End of For loop   
  }
  
  $Col1 = $val[0] ;
  $Col2 = $val[1] ;
  $Col3 = $val[2];
  
  echo $Col1;
  echo $Col2;
  echo $Col3;
  echo "&lt;br&gt;";
  
  //End of for loop
  }
  ?&gt;
  </code></pre>
  
  <p>This program works perfectly fine printing all columns and rows for n-lenght</p>
  
  <p><strong>Problem -</strong> Now our requirement is to get values of Col1, Col2, Col3 and using mysql_query compare into database and do further action. </p>
  
  <p>Minute we add anything above //End of for loop. It only iterates once and stops without throwing any php errors. </p>
  
  <p>e.g. </p>
  
  <p>.....</p>
  
  <pre><code>echo $Col1;
  echo $Col2;
  echo $Col3;
  echo "&lt;br&gt;";
  
  **$sql = mysql_query("select COALESCE(MAX(SrNo), 0)  AS Max_No from TABLEA where ColumnA = 1 and ColumnB = '$Col3'");
      $row = mysql_fetch_array($sql);
  
  
      echo $row["Max_No"];**
  
  //End of for loop
  }
  ?&gt;
  </code></pre>
  
  <p>If we add above SQL the same program only iterates once and stops? It doesn't show any errors in logs or on screen. </p>
  
  <p>Thanks in advance for your help!. </p>