Count number of records in a Mysql table with PHP?

Asked

Viewed 4,522 times

0

Guys, I have a database with a table called "users", and I would like to know how I do, 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 out!!

4 answers

1

Just do it that way here.

$sql = "SELECT * FROM usuarios";
$resultado = count($sql);
echo $resultado;
  • This Count of the result will return 1, no? Since the select already has Count...

  • 1

    now I arranged the consultation, I was wrong even

1

$query = mysql_query("SELECT count(*) as total from tabela");
$resultado = mysql_fetch_assoc($query);
echo $resultado['total'];

0

When you make an appointment at the bank, you can pass the Count:

$sql = "SELECT COUNT(*) FROM fruit WHERE calories > 100";

0

PHP has a function just to count lines without using Count(*) which is the mysqli_num_rows(). With this you can reuse the result of the query.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.