1
How do I make this count meet some criteria?
ALBERTO
CONCLUÍDO | 8 REPROVADO | 3 DUPLICADO | 4 EM ANÁLISE| 5
I need you to return this result to the screen... where:
The number represents how many records exist with this DATA in the STATUS field for the NAME field ( "ALBERTO" I will insert as filter criterion )
$conn = mysqli_connect($servidor, $usuario, $senha, $dbname);
if(!$conn)
{
echo "ERROR 1 - ERROR 1 - ERROR 1";
}
$criterioDeFiltro = "ALBERTO";
$criterioDeFiltro = mysqli_real_escape_string($conn, $criterioDeFiltro);
$sql = "SELECT count(id) AS total, nome, situacao FROM tbl_test where nome = '{$criterioDeFiltro}' group by nome, situacao";
$result = mysqli_query($conn,$sql);
while ($values = mysqli_fetch_assoc($result)) {
$num_rows = $values['total'];
echo "Nome = " . $values["nome"] . "\n";
echo "Situação = " . $values["situacao"] . "\n";
echo "Total = " . $num_rows . "\n";
echo "\n";
}
mysqli_free_result($result);
mysqli_close($conn);
echo "ERROR 2 - ERROR 2 - ERROR 2";
?>
Daniel, returning the following error, check out: Line 33: mysqli_free_result($result); ERROR MESSAGE: PHP Warning: mysqli_free_result() expects expects expects Parameter 1 to be mysqli_result, Boolean Given in
– Alberto Nascimento
I did not make that mistake, but it seems that in its application the
$result
was different than expected, check if protecting with a condition the error ceases to be generated, I made an edition in the example of the code and also in the online version, but your scenario will surely be different from the simulated, therefore a suitability may be necessary.– Daniel Mendes
I modified my "Question" where I inserted the code I am trying to use, but only ERROR 2 is displayed
– Alberto Nascimento
This means that not even connect in the bank you are getting, you saw the online example? There it is complete, creating the table and persisting data, however your application I do not know how it is, do not know the connection data with your database etc.
– Daniel Mendes
So Daniel Mendes, the "connection to the database is ok" because what is ERROR 2... the error regarding the connection is going perfectly. I put two error messages, one for CONNECTION and one for SEARCH AND COUNT. Once this is done, the error shown ( or not executing ) is the second, that is, the SEARCH AND COUNT.
– Alberto Nascimento
Yes, I realized that in the Online Example Daniel is working even better than I imagined. The problem then would be in my server? I use PHP 5.6 and PHP 7.2 ( which one should I use? )
– Alberto Nascimento
I always recommend using the latest stable version: https://www.php.net/downloads.php
– Daniel Mendes
Dear Daniel, now it is working perfectly. When I removed the "? >" at the end of the code it worked.
– Alberto Nascimento