title: PHP How to fix this strange UNDEFINED OFFSET error?
body: <p>Ok here is my model, which returns everything to my controller and forwarded to my view. <strong>I get the correct row output but I also get this strange undefined offset error.</strong></p>
  
  <p>model</p>
  
  <pre><code>function getAllCustomersPendingInstall()
  {
      $data=array();
      //Need to use sessions to display proper 
      //records for each user. Temp set id to user #7
      $id = 7;
  
      //query the db and return all record where SalesRepId == $id
      $query = $this-&gt;db-&gt;get_where('customers', array('SalesRepId' =&gt; $id));
  
          //check logic, if rows exist RETURN all rows, else
          //return message that no pending installs is available.
          if($query-&gt;num_rows &gt;= 0) {
              foreach($query-&gt;result() as $row) {
                  $data['cFirstName'][] = $row-&gt;customerFirstName;
                  $data['cLastName'] [] = $row-&gt;customerLastName;
                  $data['cId'][] = $row-&gt;customerId;
                  $data['cStatus'][] = $row-&gt;customerStatus;
                  $data['cDateSold'][] = $row-&gt;customerDateSold;
                  $data['cCorp'][] = $row-&gt;customerCorp;
                  $data['cAccount'][] = $row-&gt;customerAccount;
                  $data['cAddress'] [] = $row-&gt;customerAddress;
                  $data['cAptNum'][] = $row-&gt;customerCity;
                  $data['cState'][] = $row-&gt;customerState;
                  $data['cZip'][] = $row-&gt;customerZip;
                  $data['cEmail'][] = $row-&gt;customerEmail;
                  $data['cHomePhone'][] = $row-&gt;customerHomePhone;
                  $data['cCellPhone'][] = $row-&gt;customerCellPhone;
                  $data['cInstallDate'][] = $row-&gt;customerInstallDate;
                  $data['cInstallTime'][] = $row-&gt;customerInstallTime;    
                  $data['cServiceLevelSold'][] = $row-&gt;customerServiceLevelSold;
                  $data['cWinBackFrom'][] = $row-&gt;customerWinBackFrom;
                  $data['cSaleSource'][] = $row-&gt;customerSaleSource;
                  $data['cTier'][] = $row-&gt;customerTier;      
                  $data['mySalesRepId'][] = $row-&gt;SalesRepId;
              }
          } else {
              $data = "No pending installs available!";
              return $data;
          }   
  //the following var_dump is only showing the last record.
  //need to show all rows (which should be 2)
  //var_dump($data); exit;
  return $data;           
  }
  </code></pre>
  
  <p>view</p>
  
  <pre><code>    &lt;?php $dataNumRows = count($optimum); ?&gt;
  
      &lt;?php for ($i = 0; $i &lt; $dataNumRows; $i++) : ?&gt;
          &lt;?php echo $optimum['cFirstName'][$i]; ?&gt;
          &lt;?php echo $optimum['cLastName'][$i]; ?&gt;
          &lt;?php echo $optimum['cId'][$i]; ?&gt;
          &lt;?php echo $optimum['cStatus'][$i]; ?&gt;
          &lt;?php echo $optimum['cDateSold'][$i]; ?&gt;
          &lt;?php echo $optimum['cCorp'][$i]; ?&gt;
          &lt;?php echo $optimum['cAccount'][$i]; ?&gt;
          &lt;?php echo $optimum['cAddress'][$i]; ?&gt;
          &lt;?php echo $optimum['cAptNum'][$i]; ?&gt;
          &lt;?php echo $optimum['cState'][$i]; ?&gt;
          &lt;?php echo $optimum['cZip'][$i]; ?&gt;
          &lt;?php echo $optimum['cEmail'][$i]; ?&gt;
          &lt;?php echo $optimum['cHomePhone'][$i]; ?&gt;
          &lt;?php echo $optimum['cCellPhone'][$i]; ?&gt;
          &lt;?php echo $optimum['cInstallDate'][$i]; ?&gt;
          &lt;?php echo $optimum['cInstallTime'][$i]; ?&gt; 
          &lt;?php echo $optimum['cServiceLevelSold'][$i]; ?&gt;
          &lt;?php echo $optimum['cWinBackFrom'][$i]; ?&gt;
          &lt;?php echo $optimum['cSaleSource'][$i]; ?&gt;
          &lt;?php echo $optimum['cTier'][$i]; ?&gt;    
          &lt;?php echo $optimum['mySalesRepId'][$i]; ?&gt;
          &lt;br&gt;
      &lt;?php endfor; ?&gt;
  </code></pre>
  
  <p>The webpage is displaying my data correctly but then it shows this undefined output error </p>
  
  <pre><code>Tom Jones 1  4   02/11/2013  77  895482  1823 e15th St   Brooklyn    NY  11268   tones728@verizon.net    0000000000  0000000000  02/16/2013  1   11  1   1   1   7 
  Alexa Planter 2  4   02/13/2013  77  632584  5847 w79th Ave  Brooklyn    NY  11258   aplanter222@gmail.com   0000000000  0000000000  02/22/2013  1   31  1   1   2   7 
  A PHP Error was encountered
  
  Severity: Notice
  
  Message: Undefined offset: 2
  
  Filename: views/welcome_message.php
  
  Line Number: 29
  
  A PHP Error was encountered
  
  Severity: Notice
  
  Message: Undefined offset: 2
  
  Filename: views/welcome_message.php
  
  Line Number: 30
  
  .... repeated to line 49
  </code></pre>
  
  <p>Here is the lines causing the error:</p>
  
  <pre><code>29| &lt;?php echo $optimum['cFirstName'][$i]; ?&gt;
  30| &lt;?php echo $optimum['cLastName'][$i]; ?&gt;
  ..| &lt;?php echo $optimum['cId'][$i]; ?&gt;
  &lt;?php echo $optimum['cStatus'][$i]; ?&gt;
  &lt;?php echo $optimum['cDateSold'][$i]; ?&gt;
  &lt;?php echo $optimum['cCorp'][$i]; ?&gt;
  &lt;?php echo $optimum['cAccount'][$i]; ?&gt;
  &lt;?php echo $optimum['cAddress'][$i]; ?&gt;
  &lt;?php echo $optimum['cAptNum'][$i]; ?&gt;
  &lt;?php echo $optimum['cState'][$i]; ?&gt;
  &lt;?php echo $optimum['cZip'][$i]; ?&gt;
  &lt;?php echo $optimum['cEmail'][$i]; ?&gt;
  &lt;?php echo $optimum['cHomePhone'][$i]; ?&gt;
  &lt;?php echo $optimum['cCellPhone'][$i]; ?&gt;
  &lt;?php echo $optimum['cInstallDate'][$i]; ?&gt;
  &lt;?php echo $optimum['cInstallTime'][$i]; ?&gt; 
  &lt;?php echo $optimum['cServiceLevelSold'][$i]; ?&gt;
  &lt;?php echo $optimum['cWinBackFrom'][$i]; ?&gt;
  &lt;?php echo $optimum['cSaleSource'][$i]; ?&gt;
  ..| &lt;?php echo $optimum['cTier'][$i]; ?&gt;    
  49| &lt;?php echo $optimum['mySalesRepId'][$i]; ?&gt;
  </code></pre>