Display number of rows in mysql select

Discuss coding issues, and scripts related to PHP and MySQL.
User avatar
JanMolendijk
Posts:282
Location:Holland Rotterdam

Display number of rows in mysql select

Daily i have problems with my work today my problem is...

I try to build a Notification Popup i have for this a script what seems to work
but when i add a code i getting the numbers 1 2 3 4 from the 4 records from this user-id
but i would like to see only the total number (4)

Code: Select all

<?php 
$q=mysqli_query($conn,"select * from notice where user='".$_SESSION['user']."'");
$rr=mysqli_num_rows($q);
if(!$rr)
{
echo "<h2 style='color:red'>No any notice for You !!!</h2>";
}
else
{
$i=1;
while($row=mysqli_fetch_assoc($q))
{
echo "<Tr>";
echo "<td>".$i."</td>";

echo "</Tr>";
$i++;
}
?>
</table>
<?php }?>

Admin Posts:805
Hello,
The mysqli_num_rows() function returns the number of rows in the result set. So, in you code, you can use to display the value of the $rr variabe:

Code: Select all

$q=mysqli_query($conn,"select * from notice where user='".$_SESSION['user']."'");
$rr=mysqli_num_rows($q);
if(!$rr){
  echo "<h2 style='color:red'>No any notice for You !!!</h2>";
}
else {
  echo '<tr><td>'. $rr .'</td></tr>';
}

JanMolendijk Posts:282
Dear admin thanks for the support... But when i add your code i getting the number off all results.
I have two users... 1 user have one result, the other user have 4 results.

For now i`m 6 hours buissy to find out (lol).
Edit:
- Sorry i lookt wrong your code is the right code thanks alot admin.

Similar Topics