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 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 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 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 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 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 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 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 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 Share on other sites More sharing options...
Recommended Posts