Hi.
Having 10 database cols, in wich could have (or not) any letter, from A to J.
I need to get how many i have from each letter.
i.e: if it would be like this: A - A - C - x -D - A - E - J - E - A
(x means there's no entry).
So, i would have 4-A, 2-E, 1-C, ... ...
Using array_count_values() i get the result above (not ordered), but i need to now wich one is the letter that has "more votes"...
I looked for a function, but can't find it... and i'm stuck... can't find a way to do it...
So, my request for help is:
How can i find the "most voted" letter, so i can use it?
Thanks.
How to group results from query, in this way:
Moderator: General Moderators
Ok, i somewhat got a working way... but it looks kind of "rude".
Any suggestions?
Any suggestions?
Code: Select all
// Get letter votes
$vot = mysql_query("SELECT ...
$vot = mysql_fetch_row ($vot);
// Get them in quantity
$vot = array_count_values($vot);
// Need that result
$re = $vot;
// Copyed from manual :)
function order ($a, $b)
{
if ($a == $b) return 0;
return ($a > $b) ? -1 : 1;
};
// Getting the max. votes
usort ($re, "order");
// Dysplaying letters, and the winner gets marked with 'Letter'
for ($a=1;$a<=10;$a++)
{
if (empty($votї$a])) $votї$a] = 0;
if ($reї0] == $votї$a]) $teet = 'Letter';
else $teet = '';
echo "<br>$votї$a] $teet";
};