开发者

Redefine Row Name

开发者 https://www.devze.com 2023-03-07 05:29 出处:网络
Is it possible to redefine a rows name when I use 开发者_如何学CSELECT in MySQL? \"SELECT posts.id AS the_post_id FROM posts\"

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消