douzi1991 2015-12-27 00:14
浏览 122

将SQL查询对象转换为整数

Given the code:

$counters = $db->query("SELECT COUNT(film_id) FROM review WHERE film_id = $film_id ");

I need to convert the object $counters into an integer. FYI: the query returns a single int i.e 4 (depending on the film_ID)

  • 写回答

2条回答 默认 最新

  • dsaff82024 2015-12-27 00:19
    关注

    Give an alias to the column that stores the COUNT result then use it as you would use with any other SELECT query.

    $counters = $db->query("SELECT COUNT(film_id) AS counter FROM review WHERE film_id = $film_id ");
    $counter = $counters->fetch_assoc();
    
    echo $counter['counter'];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c++ gmssl sm2验签demo
  • ¥15 关于模的完全剩余系(关键词-数学方法)
  • ¥15 有没有人懂这个博图程序怎么写,还要跟SFB连接,真的不会,求帮助
  • ¥15 关于移动机器人坐标计算
  • ¥30 模拟电路 logisim
  • ¥15 PVE8.2.7无法成功使用a5000的vGPU,什么原因
  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音