duankousong9637 2017-04-16 20:57
浏览 52
已采纳

将数据从数据库返回到PHP作为变量[重复]

I'm trying to get a count of how many entries are in a database by using COUNT in SQL similar to this. This is my code, it returns/echos nothing.

$result=mysqli_query($con,"SELECT COUNT(id) as total FROM Customer");

if (!$result) echo mysql_error();

$row=mysqli_fetch_assoc($result);

echo $row['total'];

$id=$row['total'];

echo($id);

What is wrong? The connection info is correct and has no errors.

Update: I still need help with this. Please stop downvoting and not giving answers. If it's a question with an obvious answer please tell me.

Update: This is not at all a duplicate of that question. The issue was not specifically with error reporting.

Update: I answered this question and figured out my problem was with the default database which is why nothing was being returned. I can't select my answer until tomorrow.

</div>
  • 写回答

3条回答 默认 最新

  • duanjiu4498 2017-04-17 03:05
    关注

    I never put mysqli_select_db ( $con, "....."); Into my file so it never knew what database to use. I also was not getting errors because I was using mysql_error instead of mysqli_error. Once I selected the default database, it worked fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏