duanbarong4321 2015-06-14 10:07
浏览 21
已采纳

另一个有mysqli问题的初学者

I'm quite new to working with PHP and databases. So, like all beginners, I'm having problems with the mysqli extension. I was trying to avoid using mysqli_results, as I didn't want to deal with an array and a loop every time I want a simple piece of data. But that might not be possible.

I need to echo $user_count, but nothing seems to be stored there. My code seems to be okay according to the API, but maybe I'm just trying to use the wrong functions altogether. How do I put the result I need into $user_name?

mysqli_query($conn, "SELECT * FROM `wp_users` WHERE 1");
$result_user_count = mysqli_query($conn, "SELECT COUNT(`ID`) FROM `wp_users`");
$user_count = mysqli_fetch_field_direct($result_user_count, 0);
echo $user_count . ' users found on ' . $dbname . ':</br>';
  • 写回答

2条回答 默认 最新

  • dongqishou7471 2015-06-14 10:34
    关注

    Based on your provided code, you need to change it like below:-

    $query = mysqli_query($conn, "SELECT COUNT(ID) AS COUNT FROM wp_users") or die(mysqli_error($conn));
    
    while ($row = mysqli_fetch_assoc($query)) {
            echo "Total Users Are:- ". $row["COUNT"];
    }
    

    Note:- try to add mysqli error reporting code so that you will what problem actually exist in your query code, and you can easily resolve them. thanks

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

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器