PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
The result I get is 1. When I open MySQL Monitor and type: SELECT count(*) FROM users; I get this:
+----------+
| count(*) |
+----------+
| 11
+----------+
1 row in set (0.01 sec)
The result is 11. When I type there SELECT username FROM users; I get all 11 usernames, but why does my code displays that there are only one record? Thank you!
count(*) does the work of counting the rows for you. MySQL counts *, then puts it in one record, and outputs. So, when you are only getting one record like this, that one record contains a count of all records. You can get this information in 2 ways. The first would be to change your query to:
<?php
$query_count = "SELECT * FROM users";
$result_count = mysql_query($query_count);
$totalrows = mysql_affected_rows($result_count);
echo "$totalrows";
//$totalrows now have the affected rows by the request from $result_count
?>
?>
feyd - you're not wrong, using affected_rows on a SELECT query is utterly pointless (as is doing a SELECT * - what a complete waste of CPU! Just count it like you're supposed to).