title: SQL select data speed up
body: <p>Please help me to generate report speedy.it will take so many time to load report</p>
  
  <pre><code>for ($i = 0; $i &lt; sizeof($array_time); $i++) {
      $pdf-&gt;Cell(.36, .25, $array_time[$i], 'LTRB', 0, "C", 1);
      foreach ($array_day as $days) {
          $datefinal = $datese . $days . $array_time[$i];
          $query2 = "select * from $this-&gt;dbName.$this-&gt;dbViewTable where DATETIME LIKE '$datefinal%' AND  COMPANY_ID='$companyid' AND SITE_ID='$site_id' AND LOCATION_ID='$location_id'";
          $result = $conn-&gt;query($query2);
          $row2 = $result-&gt;fetch_assoc();
          $date = $row2['DATETIME'];
          $timec = substr($date, 6, 2) . ":" . substr($date, 8, 2) . ":" . substr($date, 10, 2);
          if ($timec == "::") {
              $imagefill = "images/colors/bg.png";
              $pdf-&gt;Cell(.36, .25, "" . $pdf-&gt;Image($imagefill, $pdf-&gt;GetX(), $pdf-&gt;GetY(), .36, .25), 'LTBR', 0, 'C');
          } else {
              $pdf-&gt;Cell(.36, .25, $timec, 'LTRB', 0, "C", 1);
          }
      }
      $pdf-&gt;Ln();
  }
  </code></pre>