0

我正在研究 WPF,当我尝试检索有关日期范围的信息时,我有两个日期选择器,它在所有日期上仅显示一条记录(同一记录显示多次,例如:从 2013 年 1 月 10 日至 2013 年 3 月 10 日选择的日期) 我每天有 3 条不同的记录,但我的输出是第一条记录显示 3 次,日期和时间相同。

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 "<h2 style=\"text-align: center;\">Permitted Vehicle Summary</h2>";
    print "<h2 style=\"text-align: center;\">for $cpName</h2>";
    $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 = &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 > \"$startDateTime\" AND entry_datetime < \"$endDateTime\" AND carpark_id=\"$cpId\" ";
        $result = $conn->Execute($sql);
        if (!$result) {
            print $conn->ErrorMsg();
            exit;
        }
        $rows = $result->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'] > 0) {
                    $dur_string .= $dur_array['days'] . ' days ';
                }
                if ($dur_array['hours'] > 0) {
                    $dur_string .= $dur_array['hours'] . ' hours ';
                }
                if ($dur_array['mins'] > 0) {
                    $dur_string .= $dur_array['mins'] . ' minutes ';
                }
                if ($dur_array['secs'] > 0) {
                    $dur_string .= $dur_array['secs'] . ' secs ';
                }
                $myArray[$plate][] = array($inDateTime, $outDateTime, $inDate, $dur_string);
            }
        }

        while ($startLoopDate < $endLoopDate) {
            $dayString = strftime("%a, %d %B %Y", $startLoopDate);
            $dayCheck = strftime("%Y-%m-%d", $startLoopDate);

            print "<h2>$dayString</h2>";
            print "<table width=\"100%\">";
            print "  <tr>";
            print "    <th>VRM</th>";
            print "    <th>Permit Group</th>";
            print "    <th>Entry Time</th>";
            print "    <th>Exit Time</th>";
            print "    <th>Duration</th>";
            print "  </tr>";
            foreach($new_platelist as $wlPlate) {
                if ($myArray[$wlPlate][0][2] == $dayCheck) { 
                print "<tr>";
                print "<td>$wlPlate</td>";
                if (isset($myArray[$wlPlate])) {
                    print "<td>".$staticWhitelistArray[$wlPlate]['groupname']."</td>";
                    print "<td>".$myArray[$wlPlate][0][0]."</td>";
                    print "<td>".$myArray[$wlPlate][0][1]."</td>";
                    print "<td>".$myArray[$wlPlate][0][3]."</td>";
                }
                else {
                    print "<td>Vehicle Not Seen</td>";
                    print "<td>Vehicle Not Seen</td>";
                    print "<td>Vehicle Not Seen</td>";
                }
                print "</tr>";
                }
            }
            print "</table>";
            $startLoopDate = $startLoopDate + $oneDay;
        }
    }
} 
4

1 回答 1

0

您能否回显此查询,以便我们查看实际发送的内容...

$sql = "
SELECT plate
     , entry_datetime
     , exit_datetime 
  FROM stats 
 WHERE plate IN ('$plate_lookup') 
   AND entry_datetime BETWEEN '$startDateTime' AND '$endDateTime'
   AND carpark_id= '$cpId';
   ";

(这不是答案,但我想使用其他格式选项)

于 2013-10-21T12:23:55.453 回答