0
I have a considerable problem: - I want to list a search for a function that does a count. I want it to be displayed at the value of notifications
The counting of notifications is done from the following code:
function count_reports_where_id($conn,$id){
//$cmd = "SELECT DISTINCT blogger_id FROM reports;";
$cmd = "SELECT blogger_id FROM reports WHERE blogger_id = '$id'";
$produtos = mysqli_query($conn,$cmd) or die(mysqli_error($conn));
$total = mysqli_num_rows($produtos);
return $total;
}
Code that lists:
$result = mysqli_query($conn,"SELECT DISTINCT blogger_id from reports ORDER BY ?????/;") or die(mysqli_error($conn));
echo
"<table border='1' padding='111'>
<tr>
<th>Blogger ID</th>
<th>Notificações</th>
<th>Opções</th>
</tr>";
while($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td>" . $row['blogger_id'] . "</td>";
echo "<td>" . count_reports_where_id($conn, $row['blogger_id']) . "</td>";
echo "<td><a href='admin_report.php?id=". $row['blogger_id'] ."'>Verificar</a></td>";
echo "</tr>";
}
echo "</table>";
How to sort the list by count_reports_where_id? function that requires blogger_id to count?
It got pretty messy, I hope someone understands
– Luan pedro
$result = mysqli_query($Conn,"SELECT DISTINCT blogger_id from Reports order by $count_reports_where_id(bloggerid) ;") or die(mysqli_error($Conn)); ?
– Luan pedro
Can you try to explain it another way? How this query would be ordered?
– Neto Costa
The return of this function is num_rows, so it would be ordering by an integer value, I can’t understand the logic.
– Neto Costa
You would have to sort the output of the function where it is called. But I think it would be better to add Count to your sql. It would save a query and improve reading. I will elaborate a response
– edson alves