这不起作用,我出于某种原因从ORDER BY参数中收到错误?
if($selected_radio == 'city')
{
$query = "SELECT name FROM City WHERE name LIKE $1 LIMIT $2 OFFSET $3 ORDER BY name ASC";
$result = pg_prepare($conn, "findCity", $query);
$result = pg_execute($conn, "findCity", array($text, $limit, $offset));
while($row = pg_fetch_assoc($result))
{
echo "<tr>";
echo "<td>" . $i . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "</tr>";
$i += 1;
}
}
很抱歉看起来我对这个网站还不熟悉并且不确定如何正确发布代码:/
答案 0 :(得分:4)
你在wrong order中有条款 - ORDER BY在LIMIT和OFFSET之前。
来自文档:
SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]
* | expression [ AS output_name ] [, ...]
[ FROM from_item [, ...] ]
[ WHERE condition ]
[ GROUP BY expression [, ...] ]
[ HAVING condition [, ...] ]
[ { UNION | INTERSECT | EXCEPT } [ ALL ] select ]
[ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ]
[ LIMIT { count | ALL } ]
[ OFFSET start ]
[ FOR { UPDATE | SHARE } [ OF table_name [, ...] ] [ NOWAIT ] [...] ]