[英]How do I add criteria to a WHERE clause?
我需要使用c.statusRP = Open的狀態過濾這些結果
$query= mysql_query("SELECT h.id, h.sid, h.did, h.nextaction, h.nextactiondate, d.company, d.name, d.surname, c.company, d.balance, d.amount from History h, Person d, Client c where h.sid=c.ref and d.id=h.did and nextactiondate between $dayEnd and $dayStart order by c.company desc");
#print $tquery;
$mydate = date("d-m-Y");
$message = "<br><br><h1>Task List for $mydate</h1><br>";
$message .= "<table border=\"1\"><tr><strong><td>Customer Ref</td><td>Client Company</td><td>Customer Ref</td><td>Other Company</td><td>Full Name</td><td>Next Action</td></strong></tr>";
while ($def = mysql_fetch_row($query)) {
$sid = $def[1];
$did = $def[2];
$nextaction = $def[3];
$nextactiondate = $def[4];
$dcompany = $def[5];
$dname = $def[6];
$dsurname = $def[7];
$ccompany = $def[8];
$dbalance = $def[9];
$damount = $def[10];
if ($dbalance == "") {
$newbalance = $damount;
}
else {
$newbalance = $dbalance;
}
switch ($nextaction) {
我嘗試添加
$query= mysql_query("SELECT h.id, h.sid, h.did, h.nextaction,
h.nextactiondate, d.company, d.name,
d.surname, c.company, d.balance,
d.amount
from History h, Person d, Client c
where h.sid=c.ref
and d.id=h.did
and nextactiondate between $dayEnd and $dayStart
order by c.company desc
WHERE c.statusRP = 'Open';");
但是然后在顯示以下內容的行上出現錯誤:
while ($def = mysql_fetch_row($query)) {
我究竟做錯了什么?
您已經有了一個WHERE
,您需要將其與AND
結合在一起,並將其放在ORDER BY
之前。
$query= mysql_query("SELECT h.id, h.sid, h.did, h.nextaction, h.nextactiondate, d.company, d.name, d.surname, c.company, d.balance, d.amount
from History h, Person d, Client c
where h.sid=c.ref
and d.id=h.did
and nextactiondate between $dayEnd and $dayStart
AND c.statusRP = 'Open'
order by c.company desc;");
附加說明: $dayEnd
和$dayStart
應該加引號,除非它們是時間戳。
您願意接受SQL注入。 mysql_ *函數已被棄用,並已從PHP7中完全刪除。 切換到PDO或mysqli,並利用准備好的語句和變量綁定,您無需擔心引用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.