The mysqli_query
returns an object and not the result query, to get the
SELECT COUNT(*)
first of a nickname uses AS
(alias):
$prevJan= "SELECT COUNT(*) as TOTAL FROM participantes WHERE PREVISTO = 'Previsto' and FORMACAO = 'Revues Techniques' and MES = 'jan' and AREA = 'R&D'";
$consultapj = mysqli_query($prevJan);
And then use fetch_assoc
, thus:
$consultapj = mysqli_query($prevJan);
if ($consultapj = mysqli_query($connection, $prevJan)) {
/* fetch associative array */
while ($row = mysqli_fetch_assoc($consultapj)) {
echo 'Total:', $row['TOTAL'];
}
/* free result set */
mysqli_free_result($consultapj);
} else {
die(mysqli_error($connection));
}
Note that I passed the $connection
in the mysqli_query
If zero returns (0
) is because or the TABLE is case-sensitive or you missed something in WHERE
[Editing]
After editing the question, the explanation of two querys is simple, fetch_array
or fetch_assoc
should preferably stay with your queries, in order and the variable row
should not be reused, because we are using to take the results inside the while/if, mixing with other variables may confuse the results:
//Variaveis para pegar os resultados
$totaPJ = 0;
$totaRJ = 0;
//qUERYS
$prevJan = "SELECT COUNT(*) AS TOTAL FROM participantes WHERE PREVISTO = 'Previsto' and FORMACAO = 'Revues Technique' and MES = 'jan' and AREA = 'R&D'";
$realJan = "SELECT COUNT(*) AS TOTAL FROM participantes WHERE REALIZADO = 'Realizado' and FORMACAO = 'Revues Technique' and MES = 'jan' and AREA = 'R&D'";
//Pega o resultado de prevJan
if ($resultado = mysqli_query($connection, $prevJan)) {
if ($row = mysqli_fetch_assoc($resultado)) {
$totaPJ = $row['TOTAL']; //Seta o total
}
mysqli_free_result($resultado);
} else {
die(mysqli_error($connection));
}
//Pega o resultado de realJan
if ($resultado = mysqli_query($connection, $realJan)) {
if ($row = mysqli_fetch_assoc($resultado)) {
$totaRJ = $row['TOTAL']; //Seta o total
}
mysqli_free_result($resultado);
} else {
die(mysqli_error($connection));
}
And on the chart will probably do so:
{
name: 'Realizado',
type: 'column',
yAxis: 1,
data: [<?php echo $totalRJ; ?>],
tooltip: {
valueSuffix: ''
}
}, {
name: 'Previsto',
type: 'spline',
data: [<?php echo $totalPJ; ?>],
tooltip: {
valueSuffix: ''
}
}
Have you seen if in the bank there really is any record that obeys the conditions of your
SELECT
?– Leandro Lima
I already checked. I created this bank myself and I know it from top to bottom. There is. :/
– Mariana Bayonetta
You can add the percentage symbol.
PREVISTO LIKE '%Previsto%'
– EmanuelF
Also check if PHP is actually connecting to the database, there is your file
conn.php
.– Leandro Lima
So, I tried to var_dump the connection, returned: Object(mysqli)#1 (0) { }
– Mariana Bayonetta
If you are in your bank manager (Workbench, phpmyadmin and etc) and give the command
SELECT COUNT(*) FROM participantes WHERE PREVISTO = 'Previsto' and FORMACAO = 'Revues Techniques' and MES = 'jan' and AREA = 'R&D
he brings something ?– Leandro Lima
So by changing to
SELECT COUNT(*) FROM
participantsWHERE PREVISTO =
PredictedAND REALIZADO =
Performed`` He gives me a count of all the predicted only.– Mariana Bayonetta