1

これは機能せず、何らかの理由で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;
    }
}

見た目が悪いので、このサイトはかなり新しく、コードを正しく投稿する方法がわかりません:/

4

1 に答える 1

4

句の順序が間違っています- 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 ] [...] ]
于 2012-09-10T22:31:18.727 に答える