douzhonglong3789 2015-12-11 00:28
浏览 58
已采纳

使用php从数据库中检索一个整数值

How do I fetch an integer value from the database?

$query = mysql_query('select number from table_name where UNIQUE_ID =SOME_UNIQUE_ID');

I am unable to access the integer value using the query above.

  • 写回答

1条回答 默认 最新

  • douzi1117 2015-12-11 01:00
    关注

    As many have commented, it's unclear what is the problem your are facing.

    The $query variable you are obtaining is NOT the integer you want but a "query object" (or False if the query failed). You have to extract at least a row using (e.g.) $t=mysql_fetch_array($query). The wanted value will be in $t[0].

    Keep in mind, anyway, that the result of a query is tipically a string, so you have to extract its integer value using intval($t[0]).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部