2014-02-06 90 views
-2
$post_items = $db->query("SELECT post_id,content,date,category_id 
     FROM post_items JOIN user ON(post_items.user_id = user.user_id) WHERE post_items.user_id =" . $userid) 

如何在我的情況下包括訂單?我試圖通過sql查詢錯誤命令

$post_items = $db->query("SELECT post_id,content,date,category_id 
     FROM post_items JOIN user ON(post_items.user_id = user.user_id) WHERE post_items.user_id =" . $userid ."order by post_id"); 

回答

0

請,應用空間場和秩序之間的關鍵字,也使用表名,如果columnaname是ambiguse查詢在哪裏使用加入:

$post_items = $db->query("SELECT post_id,content,date,category_id 
     FROM post_items inner JOIN user ON post_items.user_id = user.user_id 
     WHERE post_items.user_id =" . $userid ." order by post_items.post_id "); 
0

order之前需要一個空間:

." order by post_id" 
-1

你只需要在之前加一個空格 「ORDER BY POST_ID」 成爲 「ORDER BY POST_ID」。