-4
Good evening, this code works exactly the way I need to run directly in sql, but as I do for it to appear in a php page, I tried several things, I even managed to print but it does not appear right.
SELECT estado, COUNT(*) As Total FROM emailc WHERE status = 1 GROUP BY estado
The closest I came to the same result as the image was with this code:
$estados = mysqli_query($conexao,"SELECT * FROM `emailc` where status = 1");
while($res = mysqli_fetch_assoc($estados)){
$nomeEstado = $res['estado'];
$estadoConta = mysqli_query($conexao,"SELECT COUNT(estado) AS TOTAL FROM emailc WHERE estado LIKE '%$nomeEstado%'");
while($row = mysqli_fetch_assoc($estadoConta)){
echo '<li>'.utf8_encode($nomeEstado).' <strong>'.$row['TOTAL'].'</strong></li>'.PHP_EOL;
But repeat the state, but do the right count as shown in the image below:
I’m grateful for your help.
obviously in the last query is that the
status
, this is going to be difficult obviously. Besides, in there aLIKE
in the query, pq does not use the=
?– Ricardo Pontual
Adding the status the result remains the same, and if I put the = instead of the like, the result is 0, it does not count how many times it has the acronym RJ for ex.
– Jorge Ferreira