Php mysql查询的三元If语句
如何为$sql变量添加更多的三元if语句?当我尝试添加更多内容时,输出为空: 工作:Php mysql查询的三元If语句,php,mysql,if-statement,ternary-operator,Php,Mysql,If Statement,Ternary Operator,如何为$sql变量添加更多的三元if语句?当我尝试添加更多内容时,输出为空: 工作: $sql = "SELECT r.title,r.author,r.summary,r.posted_on,r.review_url,r.rating FROM reviews r LEFT JOIN websites w ON w.id=r.website_id WHERE w.rooftop_id=$rooftop_id
$sql = "SELECT r.title,r.author,r.summary,r.posted_on,r.review_url,r.rating
FROM reviews r
LEFT JOIN websites w
ON w.id=r.website_id
WHERE w.rooftop_id=$rooftop_id
AND review_site_id IN ($sites)
AND rating >= $star_threshold
AND review_status_id=2
" . ($pagination == 1 ? " LIMIT $offset, $review_limit " : "");
不工作:
$sql = "SELECT r.title,r.author,r.summary,r.posted_on,r.review_url,r.rating
FROM reviews r
LEFT JOIN websites w
ON w.id=r.website_id
WHERE w.rooftop_id=$rooftop_id
AND review_site_id IN ($sites)
AND rating >= $star_threshold
AND review_status_id=2
" . ($pagination == 1 ? " LIMIT $offset, $review_limit " : "")
" . ($rating_filter == 1 ? " ORDER BY r.rating " : "");
您的查询中有输入错误,请尝试以下操作:
$sql = "SELECT r.title,r.author,r.summary,r.posted_on,r.review_url,r.rating
FROM reviews r
LEFT JOIN websites w
ON w.id=r.website_id
WHERE w.rooftop_id=$rooftop_id
AND review_site_id IN ($sites)
AND rating >= $star_threshold
AND review_status_id=2
" . ($pagination == 1 ? " LIMIT $offset, $review_limit " : "")
. ($rating_filter == 1 ? " ORDER BY r.rating " : "");
就MySQL而言,
SELECT
语句中的LIMIT
子句不能位于orderby
子句之前。ORDER BY
子句必须在LIMIT
子句之前
php语法中有一个简单的问题,在您发布的最后一行代码的开头有一个额外的双引号。查看您的引号。他们错了。打开错误报告!在
php.ini
中查找error\u reporting
和display\u errors
。