2012-09-10 62 views
1

這將無法正常工作,我從ORDER BY param出於某種原因錯誤?ORDER BY不工作postgresql

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

您可以包括確切的錯誤信息? –

+0

要格式化代碼,請將其縮進4個空格或選中它並單擊'{}'按鈕。 –

+0

由於某些原因,我沒有收到錯誤消息? –

回答

4

你有你的條款在wrong order - ORDER BY去限制之前和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 ] [...] ] 
+0

是的,我知道這一點,我應該這樣做....謝謝哈哈 –