简体   繁体   English

Mysqli num_rows()返回未定义的属性

[英]Mysqli num_rows( ) returning undefined property

I'm trying to count up the amount of registered users in my database however, I am having a problem with the num_rows.. as its giving an error. 我正在尝试计算数据库中的注册用户数量,但是num_rows ..出现问题,因为它给出了错误。

Here is my index.php code: 这是我的index.php代码:

<?php
require 'connections.php';
$con->query("SELECT users, UserID from users");
$totalplayers = $con->num_rows;
?>

Here is my connections.php: 这是我的connections.php:

<?php
ob_start();
session_start();
$con = mysqli_connect("localhost", "root", "", "website");

if (isset($_SESSION['UserID'])) {
    $result = $con->query("select * from users where UserID=".$_SESSION['UserID']);
    $row = $result->fetch_assoc();

However, it is giving this error and I have no clue what to do!: 但是,它给出了此错误,我不知道该怎么办!:

Notice: Undefined property: mysqli::$num_rows in C:....\\index.php on line 4 注意:第4行的C:.... \\ index.php中的未定义属性:mysqli :: $ num_rows

you should assign the result of the query and then get the count : 您应该分配查询结果,然后获得计数:

<?php
require 'connections.php';
$result = $con->query("SELECT users, UserID from users");
// $result is a mysqli_stmt
$totalplayers = $result->num_rows;
?>

Reference: http://php.net/manual/en/mysqli-stmt.num-rows.php 参考: http : //php.net/manual/en/mysqli-stmt.num-rows.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM