0
我有一個PHP最後一個動作列表,它從MySQL獲取結果並顯示數據,但我只需要通過電話調用來定義它。 MYSQL的字段是 「類型」 和電話通話是 「P」PHP MySQL結果僅通過電話過濾
例過濾日期> $型= P
<?php
$db_host = "hidden";
$db_user = "hidden";
$database= "hidden";
$db_pwd= "hidden";
$conn = mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
mysql_select_db($database, $conn) or die(mysql_error());
$epoch = date('U');
$dayEnd = strtotime("midnight", $epoch);
$dayStart = strtotime("tomorrow", $dayEnd) - 1;
$query = mysql_query("select FROM_UNIXTIME(a.maxepoch,\"%d-%m-%Y\") , b.id, b.sid, b.did, b.type, b.nextaction, FROM_UNIXTIME(b.nextactiondate,\"%d-%m-%Y\") from History b,
(select max(epoch) as maxepoch from History
group by did) a
#where a.maxepoch = b.epoch and b.epoch < (unix_timestamp(now()) - 2592000)
where a.maxepoch = b.epoch and b.epoch < (unix_timestamp(now()) - 2419200)
order by b.epoch desc");
$mydate = date("d-m-Y");
$message = "<br><br><h1>30 day Report for $mydate</h1><br>";
$message .= "<table border=\"1\"><tr><strong><td>Client Ref</td><td>Customer Ref</td><td>Action</td><td>Action Date</td><td>Next Action</td><td>Next Action Date</td></strong></tr>";
while ($def = mysql_fetch_row($query)) {
$sid = $def[2];
$did = $def[3];
$type = $def[4];
$nextaction = $def[5];
$nextactiondate = $def[6];
$maxepoch = $def[0];
$message .= "<tr><td>$sid</td><td>$did</td><td>$type</td><td>$maxepoch</td><td>$nextaction</td><td>$nextactiondate</td></tr>";
}
mysql_free_result($query);
mysql_close($conn);
$message .= "</table>";
$message .= "</body></html>";
echo $message;
?>
從性能角度來看,我t在MySQL查詢中執行此操作要好得多,因爲@Vidalia建議:https://stackoverflow.com/a/37880398/2770263 – Kristian
是的,它是我知道的。只是OP想要稍後重用整個結果集,或者它的一部分。 – vaso123