gpt4 book ai didi

php - MySQL WHERE 的两个条件

转载 作者:行者123 更新时间:2023-11-29 13:15:25 25 4
gpt4 key购买 nike

我的错误是:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 2 行的 ') AND (tblforecast.Issued like '%01-07%' ))order by tblforecast.Issued DESC' 附近使用的正确语法

我的代码是:

$news = "SELECT tblforecast.Fore_ID, tblforecast.Issued, 
tblforecast.Synopsis,tblforecast.Forecaster, tblusers.FirstName,
tblusers.LastName FROM tblforecast
INNER JOIN tblusers ON tblusers.UserNumber = tblforecast.forecaster
WHERE ((tblforecast.Valid =$type)
AND (tblforecast.Issued like '%$filter%' ))
order by tblforecast.Issued DESC";

如果我的 WHERE 语句中只有一个条件,则它有效。

$type 为 24 或 12。$filter 为数字形式的“mm-dd”。

执行后,将继续显示新闻,内容为:

$loadnews = mysql_query($news);

if (!($loadnews))
echo mysql_error();

while($waiting = mysql_fetch_array($loadnews))
{
$NiD = $waiting['Fore_ID'];
$thedate = $waiting['Issued'];
$synop = $waiting['Synopsis'];
$forecaster = $waiting['FirstName']." ".$waiting['LastName'];

$dDate = strtotime($thedate);
$newDate = date('F j, Y',$dDate);
echo "<div class='well well-large'>
<p><b>$newDate</b>
<br><small><i>$forecaster</i></small>
<br>$synop</p>
<br><small><a href='pdetails.php?NiD=$NiD'>Read More</a></small></p>
</div>";
}
<小时/>

响应对$news内容的请求,这是它在赋值语句之后保存的内容:

SELECT tblforecast.Fore_ID, tblforecast.Issued, tblforecast.Synopsis,tblforecast.Forecaster, tblusers.FirstName, tblusers.LastName FROM tblforecast INNER JOIN tblusers ON tblusers.UserNumber = tblforecast.forecaster WHERE ((tblforecast.Valid =) AND (tblforecast.Issued like '%01-07%' ))order by tblforecast.Issued DESC

最佳答案

尝试

AND (tblforecast.Issued like '%' + $filter + `%' ))  
// or whatever is right for PHP

但更重要的是,在尝试在 sql 中使用变量之前,请确保已设置变量。

关于php - MySQL WHERE 的两个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21522427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com