Jump to content

[SOLVED] counting / arrays


xXREDXIIIXx

Recommended Posts

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 />";

}

Link to comment
https://forums.phpfreaks.com/topic/177951-solved-counting-arrays/
Share on other sites

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]}";

}

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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.