Redefine Row Name
Is it possible to redefine a rows name when I use 开发者_如何学CSELECT
in MySQL
?
"SELECT posts.id AS the_post_id FROM posts"
So I can call it from PHP as:
$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"];
}
Yes, you have already done it correctly. Are you having issues with that?
Edit:
$query = mysql_query("SELECT posts.id AS the_post_id FROM posts") or die(mysql_error());
Try it like that and it would tell you if there is any issue with the query itself. Also i would suggest you look at the newer mysqli_* functions, mysql_* functions are history.
精彩评论