Counter of records or columns of a Mysql database using PHP

0

I would like to know the total of numbers of columns or records entered in a table and display it on the screen.

For example, in the table I have three records or columns and I need you to give me the number 3

What I have is the following

 global $connect;


$query = "SELECT count(*) as total from Asistente ";

mysqli_query($connect, $query) or die (mysqli_error($connect));

    $data=mysqli_fetch_assoc($result);

    echo $data['total'];


mysqli_close($connect);

error message

  

mysqli_fetch_assoc () expects parameter 1 to be mysqli_result, null   given in

    
asked by Ashley G. 05.02.2017 в 18:00
source

2 answers

1

you need to assign a value to your variable $result

global $connect;


$query = "SELECT count(*) as total from Asistente ";

if ($result = mysqli_query($connect, $query)) {

    $data=mysqli_fetch_assoc($result);

    echo $data['total'];

}
mysqli_close($connect);
    
answered by 05.02.2017 / 18:48
source
0

If you put the $ query instead of the $ result? Because that's why it tells you that a value is null, since there is no $ result.

global $connect;


$query = "SELECT count(*) as total from Asistente ";

mysqli_query($connect, $query) or die (mysqli_error($connect));

    $data=mysqli_fetch_assoc($query);

    echo $data['total'];


mysqli_close($connect);
    
answered by 05.02.2017 в 18:49