Just so you know why your code did not work as expected: for the simple fact that you were using field_count
which:
Returns the number of columns for the most recent query
In fact, your code was this:
<?php echo $ticket->pendientesporrevisar($conexion)->field_count; ?>
and it always returned 1
because you were recovering the number of columns, not the value of them.
Anyway, it's good to standardize the SQL code, using AND
instead of &&
, even if it works in both ways.
In any case, the problem was in reading the information you were implementing .
It is important to know that there are several ways to obtain the results, using the different fetch
methods. Perhaps, for the code to be more readable, it is convenient to use fetch_assoc
, I put a example to expand the range of possibilities:
function pendientesporrevisar($conexion){
$pendientes = (mysqli_query($conexion, "SELECT COUNT(*) conteo FROM ticket WHERE tipo_solicitud = 1 && status = 1 ")) or die("Error mostrando tickets pendientes: ".mysqli_error($conexion));
$resultados = mysqli_fetch_assoc($pendientes);
$total = ($resultados && $resultados["conteo"]>0) ? $resultados["conteo"] : NULL ;
return $total;
}
In the function I have also added a supplementary control: using a ternary operator to evaluate the attempt to obtain the data, I assign the variable $total
the result obtained or NULL
, in case there is any problem ... The value NULL
can be replaced by 0
, for a blank string ''
or otherwise if you prefer.