I don't know if this is actually it, but the line
$num_vals[$i] = mysql_fetch_array($result);
seems strange to me - doesn't mysql_fetch_array return an array? You should try
list($num_vals[$i]) = mysql_fetch_array($result);
and see if you get any improvements...

Daniel Alsén wrote:

> I have worked this over in my head over the holidays and still haven´t got a
> solution. Can anyone help?
>
> I have a MySql table populated with numerical values from 0 to 10 in five
> different fields. I need a function that counts all occurances of each
> value, ie: 1: 12, 2: 3, 4: 74 etc...
>
> I have worked with this code:
>
> $num_vals = array ();
> for ($i=0; $i<10; $i++)
> {
> $shot_count = "SELECT COUNT(*) FROM statistik WHERE shooter='$shooter_login'
> AND ((shot_one = '$i') OR
> (shot_two = '$i') OR (shot_three = '$i') OR
> (shot_four = '$i') OR (shot_five = '$i'))";
>
> $result = mysql_query($shot_count);
> $num_vals[$i] = mysql_fetch_array($result);
> }
>
> The code works...but returns the wrong results. If i count from the database
> manually there is always some occurances missing.
>
> So, today i tried to count the values from an array instead:
>
> $shotcount = "SELECT shot_one, shot_two, shot_three, shot_four, shot_five
> FROM statistik WHERE shooter='$shooter_login'";
> $results = mysql_query($shotcount);
> $bam = mysql_fetch_array($results);
>
> $count = array_count_values ($bam);
>
> while (list($key,$value) = each($count)) {
> echo "$key : $value<br>";
> }
>
> But this works even worse...it seems to stop populating the array (or
> counting the values) after only a couple of rows from the db. The result
> looks like:
> 3 : 4
> 5 : 2
> 7 : 2
> 9 : 2
> And there should be alot more of those keys...and a couple of keys more as
> well...
>
> I would appreciate any help on this guys. I am soooo stuck :(
>
> # Daniel Alsén    | www.mindbash.com #
> # [EMAIL PROTECTED]  | +46 704 86 14 92 #
> # ICQ: 63006462   | +46 8 694 82 22  #
> # PGP: http://www.mindbash.com/pgp/  #
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to