onedumbcoder Posted September 8, 2009 Share Posted September 8, 2009 select count(id) from user WHERE age > 33 now when i execute that query how to i echo that value? $result = mysql_query('select count(id) from user WHERE age > 33'); $count = mysq_fetch_array($result); echo $count[???]; Link to comment https://forums.phpfreaks.com/topic/173581-how-do-you-each-the-value-countid/ Share on other sites More sharing options...
Maq Posted September 8, 2009 Share Posted September 8, 2009 Read: http://www.tizag.com/mysqlTutorial/mysqlcount.php Link to comment https://forums.phpfreaks.com/topic/173581-how-do-you-each-the-value-countid/#findComment-914949 Share on other sites More sharing options...
cbolson Posted September 8, 2009 Share Posted September 8, 2009 Hi, you can do it like this: $result = mysql_query('select count(id) AS total from user WHERE age > 33'); $count = mysq_fetch_array($result); echo $count["total"]; Chris Link to comment https://forums.phpfreaks.com/topic/173581-how-do-you-each-the-value-countid/#findComment-914950 Share on other sites More sharing options...
onedumbcoder Posted September 8, 2009 Author Share Posted September 8, 2009 try this $result = mysql_query("select id AS total from user WHERE age > 33"); echo mysql_num_rows($result); Link to comment https://forums.phpfreaks.com/topic/173581-how-do-you-each-the-value-countid/#findComment-914960 Share on other sites More sharing options...
onedumbcoder Posted September 8, 2009 Author Share Posted September 8, 2009 try this $result = mysql_query("select id AS total from user WHERE age > 33"); echo mysql_num_rows($result); Thanks so much, that did it. Link to comment https://forums.phpfreaks.com/topic/173581-how-do-you-each-the-value-countid/#findComment-914962 Share on other sites More sharing options...
corbin Posted September 8, 2009 Share Posted September 8, 2009 Don't do it like that. I don't feel like getting into the details, but that pulls all of the rows and then counts them. If you only care how many rows there are, get MySQL to send back that. $q = mysql_query("SELECT COUNT(blah) FROM bleh"); $r = mysql_fetch_row($q); echo $r[0]; Link to comment https://forums.phpfreaks.com/topic/173581-how-do-you-each-the-value-countid/#findComment-915056 Share on other sites More sharing options...
onedumbcoder Posted September 8, 2009 Author Share Posted September 8, 2009 off topic, but corbin are you by any chance racist? I got that eerie feeling reading your post. Link to comment https://forums.phpfreaks.com/topic/173581-how-do-you-each-the-value-countid/#findComment-915073 Share on other sites More sharing options...
Maq Posted September 9, 2009 Share Posted September 9, 2009 off topic, but corbin are you by any chance racist? I got that eerie feeling reading your post. Please elaborate. What in his post suggest racism? Link to comment https://forums.phpfreaks.com/topic/173581-how-do-you-each-the-value-countid/#findComment-915372 Share on other sites More sharing options...
fenway Posted September 10, 2009 Share Posted September 10, 2009 I can't see this ending well. Link to comment https://forums.phpfreaks.com/topic/173581-how-do-you-each-the-value-countid/#findComment-916307 Share on other sites More sharing options...
Recommended Posts