douzhonglong3789 2015-12-11 08: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 09: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]).

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

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试