Forum Moderators: coopster
I could use some insight into solving what should be an easy task. Example:
I want to randomly select 5 cards from a standard playing card deck and count how many of each suit are returned:
[connect]
$sql = "SELECT * FROM cards ORDER BY RAND()LIMIT 5";
$result = mysql_query($sql);
while($cards = mysql_fetch_array($result)) {
$value = $cards["card_value"];
$suit = $cards["card_suit"];
$image = $cards["card_image"];
--------
Using count() within the loop returns a count of 1 since each card can only be of one suit. I tried using something like this:
$spades = 0;
if($suit='spades') {
$spades = $spades+1;
}
and I tried a foreach statement to count within the loop which always returns a count of 1.
Would someone be so kind as to point me in the right direction?
RS
if($card_suit == 'spades') {
$spades=$spades+1;
}
if($card_suit == 'hearts') {
$hearts=$hearts+1;
}
if($card_suit == 'clubs') {
$clubs=$clubs+1;
}
if($card_suit == 'diamonds') {
$diamonds=$diamonds+1;
}
and then printed the counts outside the loop and everything is being counted correctly now. Thanks...
${$card_suit}++;