xXREDXIIIXx Posted October 16, 2009 Share Posted October 16, 2009 hey probably a simple one but I am trying to count the number of games who play or have played a specific game represented by a number, the gameid example: a gamer selects all the games the have played by checking the boxes and then it saves into an array or gameids: 1, 2, 3, 6, 14, 25 etc... what i need to do is get that arrays from my gamers... easy but pick out the specific number for each game below is my code to show arrays $query = mysql_query("SELECT cgames FROM gamers"); while($grow = mysql_fetch_array($query)){ echo $grow['cgames']. "<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/177951-solved-counting-arrays/ Share on other sites More sharing options...
teynon Posted October 16, 2009 Share Posted October 16, 2009 Your wording is kind of confusing, but i'll try to put it together: It looks like your SQL database is using cgames as your game ID. So your db might look like this: Field 1, Field 2, cgames, Player name blah, blah, 2, Tom blah, blah2, 2, Joe If this is the case, then the easiest thing for you to do is this: $query="SELECT cgames,count(cgames) FROM gamers GROUP BY cgames"; while ($grow = mysql_fetch_array($query)) { echo "game ID: {$grow['cgames']} Players: {$grow[1]}"; } Quote Link to comment https://forums.phpfreaks.com/topic/177951-solved-counting-arrays/#findComment-938277 Share on other sites More sharing options...
xXREDXIIIXx Posted October 16, 2009 Author Share Posted October 16, 2009 Your wording is kind of confusing, but i'll try to put it together: It looks like your SQL database is using cgames as your game ID. So your db might look like this: Field 1, Field 2, cgames, Player name blah, blah, 2, Tom blah, blah2, 2, Joe If this is the case, then the easiest thing for you to do is this: $query="SELECT cgames,count(cgames) FROM gamers GROUP BY cgames"; while ($grow = mysql_fetch_array($query)) { echo "game ID: {$grow['cgames']} Players: {$grow[1]}"; } sorry if it was confusing but i solved it anyway just change 9 to the game id number but that will be automatic form my code anyway thanks for help. $numbers = mysql_query("SELECT cgames FROM gamers"); while($grow = mysql_fetch_array($numbers)){ $nums = $grow['cgames']; $array = explode(", ",$nums); $value = '9'; if(in_array($value, $array)){$i++;} } echo $i; Quote Link to comment https://forums.phpfreaks.com/topic/177951-solved-counting-arrays/#findComment-938283 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.