Count number of records in a MySql table with PHP?

0

People, I have a database with a table called "users", and I would like to know how I can, through PHP, count how many records there are in this table, and then give an echo to show this amount on the page. Please help me !!

    
asked by anonymous 02.06.2018 / 17:22

4 answers

1

Just do it that way here.

$sql = "SELECT * FROM usuarios";
$resultado = count($sql);
echo $resultado;
    
04.06.2018 / 18:41
0

When you make a query in the database, you can pass Count:

$sql = "SELECT COUNT(*) FROM fruit WHERE calories > 100";
    
02.06.2018 / 23:52
0
$query = mysql_query("SELECT count(*) as total from tabela");
$resultado = mysql_fetch_assoc($query);
echo $resultado['total'];
    
04.06.2018 / 18:47
0

PHP has a function only to count the rows without using Count(*) which is mysqli_num_rows() . This allows you to reuse the query result.

$QUERY = "SELECT * AS Quantidade FROM BancoA.tabelaA";
$executa_query = mysqli_query($conexao, $QUERY);
$conta_linhas = mysqli_num_rows($executa_query);
echo $conta_linhas;
    
04.06.2018 / 19:20