使用限制和PHP中的位置

时间:2015-11-19 11:45:45

标签: php selection limit

我用PHP编写了这段代码。

$result = mysqli_query($connection, "SELECT * FROM app WHERE" . $_REQUEST['filter']  . " ORDER BY " . $_REQUEST['sort']);

$output = array();
while($row = mysqli_fetch_array($result)) {
    $record = array();
    $record['app_id'] = $row['app_id'];
    $record['app_name'] = $row['app_name'];

    $output[] = $record;
}

我也想使用LIMIT。

当我在..... " ORDER BY " . $_REQUEST['sort'] "LIMIT 3");使用LIMIT时 它给了我这个错误: filter = 1 = 1 sort = 1 = 1

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in ....service.php on line 80

我该怎么做? 提前谢谢

1 个答案:

答案 0 :(得分:1)

将其附加到查询中:

mysqli_query($connection, "SELECT * FROM app WHERE" . $_REQUEST['filter'] " ORDER BY " . $_REQUEST['sort'] . " LIMIT 1,1");