frijole Posted February 2, 2008 Share Posted February 2, 2008 how can i count the number of rows in a DB and echo the amount? I would like to list the number of people signed up for an email list. Quote Link to comment https://forums.phpfreaks.com/topic/89003-solved-how-can-i-count-the-number-of-rows-in-a-db-and-echo-the-amount/ Share on other sites More sharing options...
trq Posted February 2, 2008 Share Posted February 2, 2008 <?php $sql = "SELECT COUNT(id) AS cnt FROM emaillist"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo "There are {$row['cnt']} users on the email list"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/89003-solved-how-can-i-count-the-number-of-rows-in-a-db-and-echo-the-amount/#findComment-455810 Share on other sites More sharing options...
laffin Posted February 2, 2008 Share Posted February 2, 2008 one of 2 ways // U can do this $res=mysql_query('SELECT COUNT(*) FROM users'); echo mysql_result($res,0,0); echo '<BR>'; // or U can do this $$res=mysql_query('SELECT * FROM users'); echo mysql_num_rows($res); Quote Link to comment https://forums.phpfreaks.com/topic/89003-solved-how-can-i-count-the-number-of-rows-in-a-db-and-echo-the-amount/#findComment-455816 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.