I want to find out the total number of users in the the table, "username" there are, how do I do this? I've tried a few ways, but nothing has worked. Thanks.
use the query
$sql = "SELECT COUNT(*) AS count_users FROM table_name;" $result = mysql_query($sql); $arr = mysql_fetch_array($result); echo $arr['count_users'];
Hi,
I don't understand the, "AS count_users" part. Could you please explain? Thanks. 🙂
See the MySQL docs. Its called 'aliasing'. "AS" is used to create an alias.
Is there any other way of doing this?
ya we can do it another way, any reason why not to choose the above way?
$sql = "SELECT COUNT(*) FROM table_name;" $result = mysql_query($sql); list($count_users) = mysql_fetch_row($result); echo $count_users;
Thanks for that. 🙂 No particular reason, just curious to see what other ways there are of doing this. I find the second way easier for some reason. Thanks for both solutions! 🙂