Jump to content

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;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.