Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mysql查询的三元If语句_Php_Mysql_If Statement_Ternary Operator - Fatal编程技术网

Php mysql查询的三元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变量添加更多的三元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
        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