在MySQL中使用SELECT时,是否可以重新定义行名
"SELECT posts.id AS the_post_id FROM posts"所以我可以在PHP中这样调用它:
$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"];
}发布于 2011-05-21 17:47:24
是的,你已经做得很正确了。你对此有意见吗?
编辑:
$query = mysql_query("SELECT posts.id AS the_post_id FROM posts") or die(mysql_error());尝试这样做,它会告诉您查询本身是否有任何问题。另外,我建议您查看较新的mysqli_*函数,因为mysql_*函数已成为历史。
https://stackoverflow.com/questions/6080924
复制相似问题