title: Undefined offset errorin 1 in php
body: <p>I couldn't find the error in indexing.Can you please help me to fix this up.
  Error is in the second loop of the fancyTable function.</p>
  
  <blockquote>
    <p>Error is something like this Undefined offset in 0, Undefined offset
    in 1, Undefined offset in 2, Undefined offset in 3</p>
  </blockquote>
  
  <pre><code>class PDF extends FPDF {
  
  
  function LoadData() {
      //Read file lines
      $con = new Connection();
      $connect = $con-&gt;getConnection();
  
      $sector = $_POST['text_sector'];
      $start_yr = $_POST['text_start_year'];
      $end_yr = $_POST['text_end_year'];
  
      if ($start_yr != '' || $end_yr != '') {
          if ($end_yr == '') {
              $end_yr = date("Y-m-d");
          }
          if ($start_yr == '') {
              $start_yr = strtotime('' . date("Y-m-d") . ' -10 year');
              $start_yr = date("Y-m-d", $start_yr);
          }
  
          //echo $start_yr;
          //echo $end_yr;
          $sql = "sql is too long to write here";                
      } else {
  
          $sql = 'sql is too long to write here';
      }
  
      $result = mysqli_query($connect, $sql);
      $dataArray = array(); // make a new array to hold all your data
      $index = 0;
      while ($row = mysqli_fetch_assoc($result)) { 
          $dataArray[$index] = $row;
          $index++;
      }
      return $dataArray;
  }
  
  
  function FancyTable($header, $data) {
      $this-&gt;SetFillColor(255, 0, 0);
      $this-&gt;SetTextColor(255);
      $this-&gt;SetDrawColor(128, 0, 0);
      $this-&gt;SetLineWidth(.3);
      $this-&gt;SetFont('', 'B');
      //Header
  
      $w = array(25, 50, 25, 25, 35);
      for ($i = 0; $i &lt; count($header); $i++) {
          $this-&gt;Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
      }
      $this-&gt;Ln();
  
      //Color and font restoration
      $this-&gt;SetFillColor(224, 235, 255);
      $this-&gt;SetTextColor(0);
      $this-&gt;SetFont('');
      //Data
      $fill = 0;
  
      foreach ($data as $row) {
          //$pdf-&gt;Cell($w, $h, $txt, $border, $ln, $align)
          $this-&gt;Cell($w[0], 6, $row[0], 'LR', 0, 'L', $fill);
          $this-&gt;Cell($w[1], 6, $row[1], 'LR', 0, 'L', $fill);
          $this-&gt;Cell($w[2], 6, $row[2], 'LR', 0, 'L', $fill);
          $this-&gt;Cell($w[3], 6, $row[3], 'LR', 0, 'L', $fill);
          $this-&gt;Cell($w[4], 6, number_format($row[4]), 'LR', 0, 'R', $fill);
          $this-&gt;Ln();
          $fill = !$fill;
      }
  
      $this-&gt;Cell(array_sum($w), 0, '', 'T');
  }
  
  }
  
  $pdf = new PDF();
  //Column titles
  $header = array(' No', 'Name', 'Client', 'Completed Date', 'Total Amount');
  
  $dataArray = $pdf-&gt;LoadData();
  
  $pdf-&gt;SetFont('Arial', '', 12);
  $pdf-&gt;AddPage();
  $pdf-&gt;FancyTable($header, $dataArray);
  
  $pdf-&gt;Output();
  ?&gt; 
  </code></pre>