Skip to content

Instantly share code, notes, and snippets.

@FelipeGrijo
Last active June 26, 2017 06:27
Show Gist options
  • Save FelipeGrijo/86d8f0cf496defa4910d8fc70a67f943 to your computer and use it in GitHub Desktop.
Save FelipeGrijo/86d8f0cf496defa4910d8fc70a67f943 to your computer and use it in GitHub Desktop.
Contar quantidade de ids de um banco de dados usando mysqli
<?php
//https://gist.github.com/FelipeGrijo
$host = 'localhost';//Endereco
$user = 'root';//Usuario
$pass = '';//Senha
$db = 'contas2';//Nome do banco de dados
$mysqli = new mysqli($host,$user,$pass,$db);
$sql="SELECT count(id) AS total FROM usuarios";//usuarios = nome da tabela
//$sql="SELECT count(id) AS total FROM usuarios where ativo='0'";
$result=mysqli_query($mysqli,$sql);
$values=mysqli_fetch_assoc($result);
$num_rows=$values['total'];
echo $num_rows;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment