2011-05-21 31 views
0

當我在MySQL中使用SELECT時,是否可以重新定義行名?重新定義行名

$query = mysql_query("SELECT posts.id AS the_post_id FROM posts"); 

while($row = mysql_fetch_array($query)){ 
    // I call the ID with `the_post_id` and not `id` 
    echo $row["the_post_id"]; 
} 

回答

1

是的,你已經正確地完成它:

"SELECT posts.id AS the_post_id FROM posts" 

所以我可以從PHP作爲調用它。你有問題嗎?

編輯:

$query = mysql_query("SELECT posts.id AS the_post_id FROM posts") or die(mysql_error()); 

試試看這樣的,它會告訴你,如果有一個與查詢本身的任何問題。另外我建議你看看最新的mysqli_ *函數,mysql_ *函數是歷史。

+0

哈哈,你確定嗎?真的不適合我:))那麼我會再次看看我的代碼 – Adam 2011-05-21 09:48:41

+0

哈哈它的工作我只是沒有看到它pff xD – Adam 2011-05-21 09:50:14

+0

哈哈好吧:) – 2011-05-21 09:51:15