This won't work and i'm getting an error from the ORDER BY param for some reason?
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;
}
}
Sorry about the way it looks I'm fairly new to this site and not sure how to correctly post code :/
You've got your clauses in the wrong order - ORDER BY goes before LIMIT and OFFSET.
From the docs:
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 ] [...] ]