title: retrieve data based on date range using mysql ,php
body: <p>I am working on WPF where I have two datepickers when I try  to retrieve the information on date range it displays only one record on all dates(same record displaying multiple times eg : date chosen from 01/10/2013 - 3/10/2013) where I have 3 different records on each day but my output is the first record displayed 3 times with same date and time. </p>
  
  <pre><code>function cpWhitelistStats() {
      $startDate = $_POST['startDate'];
      $startDateTime = "$startDate 00:00:00";
      $endDate = $_POST['endDate'];
      $endDateTime = "$endDate 23:59:59";
      $cpId = $_POST['id'];
      $cpName = etCommonCpNameById($cpId);
  
      print "&lt;h2 style=\"text-align: center;\"&gt;Permitted Vehicle Summary&lt;/h2&gt;";
      print "&lt;h2 style=\"text-align: center;\"&gt;for $cpName&lt;/h2&gt;";
      $tmpDate = explode("/", $startDate);
      $startYear = $tmpDate[2];
      $startMonth= $tmpDate[1];
      $startDay = $tmpDate[0];
      $tmpDate = explode("/", $endDate);
      $endYear = $tmpDate[2];
      $endMonth= $tmpDate[1];
      $endDay = $tmpDate[0];
  
      $startDateTime = "$startYear-$startMonth-$startDay 00:00:00";
      $endDateTime = "$endYear-$endMonth-$endDay 23:59:59";
  
      $custId = $_SESSION['customerID'];
      $realCustomerId = $_SESSION['realCustomerId'];
  
      $maxVal = 0;
  
      if ($custId != "") {
          $conn = &amp;newEtConn($custId);
          // Get the whitelist plates
          $staticWhitelistArray = etCommonMkWhitelist($conn, $cpId);
          array_shift($staticWhitelistArray);
  
          $startLoopDate = strtotime($startDateTime);
          $endLoopDate = strtotime($endDateTime);
          $oneDay = 60 * 60 * 24;
  
          // Get the entries
          $plateList = array_keys($staticWhitelistArray);
          $plate_lookup = implode('","', $plateList);
          $sql = "SELECT plate, entry_datetime, exit_datetime FROM stats WHERE plate IN (\"$plate_lookup\") AND entry_datetime &gt; \"$startDateTime\" AND entry_datetime &lt; \"$endDateTime\" AND carpark_id=\"$cpId\" ";
          $result = $conn-&gt;Execute($sql);
          if (!$result) {
              print $conn-&gt;ErrorMsg();
              exit;
          }
          $rows = $result-&gt;fields;
          if ($rows != "") {
              unset($myArray);
              foreach($result as $values) {
                  $plate = $values['plate'];
                  $new_platelist[] = $plate;
                  $inDateTime = $values['entry_datetime'];
                  $outDateTime = $values['exit_datetime'];
                  $tmp = explode(' ', $inDateTime);
                  $inDate = $tmp[0];
                  $in_ts = strtotime($inDateTime);
                  $out_ts = strtotime($outDateTime);
                  $duration = $out_ts - $in_ts;
                  $dur_array = intToDateArray($duration);
                  $dur_string = '';
                  if ($dur_array['days'] &gt; 0) {
                      $dur_string .= $dur_array['days'] . ' days ';
                  }
                  if ($dur_array['hours'] &gt; 0) {
                      $dur_string .= $dur_array['hours'] . ' hours ';
                  }
                  if ($dur_array['mins'] &gt; 0) {
                      $dur_string .= $dur_array['mins'] . ' minutes ';
                  }
                  if ($dur_array['secs'] &gt; 0) {
                      $dur_string .= $dur_array['secs'] . ' secs ';
                  }
                  $myArray[$plate][] = array($inDateTime, $outDateTime, $inDate, $dur_string);
              }
          }
  
          while ($startLoopDate &lt; $endLoopDate) {
              $dayString = strftime("%a, %d %B %Y", $startLoopDate);
              $dayCheck = strftime("%Y-%m-%d", $startLoopDate);
  
              print "&lt;h2&gt;$dayString&lt;/h2&gt;";
              print "&lt;table width=\"100%\"&gt;";
              print "  &lt;tr&gt;";
              print "    &lt;th&gt;VRM&lt;/th&gt;";
              print "    &lt;th&gt;Permit Group&lt;/th&gt;";
              print "    &lt;th&gt;Entry Time&lt;/th&gt;";
              print "    &lt;th&gt;Exit Time&lt;/th&gt;";
              print "    &lt;th&gt;Duration&lt;/th&gt;";
              print "  &lt;/tr&gt;";
              foreach($new_platelist as $wlPlate) {
                  if ($myArray[$wlPlate][0][2] == $dayCheck) { 
                  print "&lt;tr&gt;";
                  print "&lt;td&gt;$wlPlate&lt;/td&gt;";
                  if (isset($myArray[$wlPlate])) {
                      print "&lt;td&gt;".$staticWhitelistArray[$wlPlate]['groupname']."&lt;/td&gt;";
                      print "&lt;td&gt;".$myArray[$wlPlate][0][0]."&lt;/td&gt;";
                      print "&lt;td&gt;".$myArray[$wlPlate][0][1]."&lt;/td&gt;";
                      print "&lt;td&gt;".$myArray[$wlPlate][0][3]."&lt;/td&gt;";
                  }
                  else {
                      print "&lt;td&gt;Vehicle Not Seen&lt;/td&gt;";
                      print "&lt;td&gt;Vehicle Not Seen&lt;/td&gt;";
                      print "&lt;td&gt;Vehicle Not Seen&lt;/td&gt;";
                  }
                  print "&lt;/tr&gt;";
                  }
              }
              print "&lt;/table&gt;";
              $startLoopDate = $startLoopDate + $oneDay;
          }
      }
  } 
  </code></pre>