graham23s Posted May 6, 2007 Share Posted May 6, 2007 Hi Guys, when people register on my website they are from different countries etc, i was wondering if there was a way to display statistics e.g "14 users from united states" i know how to do mysql_num_rows for the total users but i was wondering what the query would be for specific information. thanks for nay help Graham Quote Link to comment https://forums.phpfreaks.com/topic/50261-solved-statistics-from-mysql/ Share on other sites More sharing options...
MadTechie Posted May 6, 2007 Share Posted May 6, 2007 it would be something like this SELECT country, count(*) as Total Group By country the 2 field you pull will be Total = number of entrys per country country = the counter your get a row per country as a note i am drained and didn't test the above, Quote Link to comment https://forums.phpfreaks.com/topic/50261-solved-statistics-from-mysql/#findComment-246722 Share on other sites More sharing options...
Barand Posted May 6, 2007 Share Posted May 6, 2007 Needs "FROM tablename" in there SELECT country, count(*) as Total FROM tablename Group By country Quote Link to comment https://forums.phpfreaks.com/topic/50261-solved-statistics-from-mysql/#findComment-246736 Share on other sites More sharing options...
MadTechie Posted May 6, 2007 Share Posted May 6, 2007 Knew it didn't look right!! Quote Link to comment https://forums.phpfreaks.com/topic/50261-solved-statistics-from-mysql/#findComment-246739 Share on other sites More sharing options...
graham23s Posted May 6, 2007 Author Share Posted May 6, 2007 Hi Guys, i have this so far (i know it's wrong lol) $query = "SELECT country, count(*) as Total FROM membership Group By United States"; $result = mysql_query($query) or die (mysql_error()); when you say "country" do you mean the actual country name or the row in my membership table called country? also how would i echo out the rows at all? thanks for the help guys Graham Quote Link to comment https://forums.phpfreaks.com/topic/50261-solved-statistics-from-mysql/#findComment-246820 Share on other sites More sharing options...
Barand Posted May 6, 2007 Share Posted May 6, 2007 $query = "SELECT country, count(*) as Total FROM membership Group By country"; $result = mysql_query($query) or die (mysql_error()); while (list ($country, $total) = mysql_fetch_row($result)) { echo "$country : $total <br>"; } Quote Link to comment https://forums.phpfreaks.com/topic/50261-solved-statistics-from-mysql/#findComment-246822 Share on other sites More sharing options...
graham23s Posted May 6, 2007 Author Share Posted May 6, 2007 Thanks mate. Graham Quote Link to comment https://forums.phpfreaks.com/topic/50261-solved-statistics-from-mysql/#findComment-246834 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.