Sorting
Newbie here:
can anyone help me, i've been beating my brain on this one.
how can i sort from highest to lowest for $player_wins[$i] ??
echo "<table width='300' border='1' cellspacing='0' cellpadding='2' bgcolor='#FBFFC6'>";
echo "<tr><th width='180'>Player</th><th width='40'>Won</th><th width='40'>lost</th><th
width='40'>Avg.</th>";
for($i=0;$i<=$counter;$i++){
if ($player_name[$i] != ""){
$avg = ($player_wins[$i]/($player_wins[$i]+$player_loss[$i]));
echo
"<tr><td>".$player_name[$i]."</td><td>".$player_wins[$i]."</td><td>".$player_loss[$i]."</td><td>".round($avg,3)."</td></tr>";
}
}
echo "</table>";
Re: Sorting
<comatose> wrote in message
news:m3uut2t6kggs59nhm6j6v0anl6bi5j77ni [at] 4ax.com...
| Newbie here:
| can anyone help me, i've been beating my brain on this one.
| how can i sort from highest to lowest for $player_wins[$i] ??
|
|
|
|
| echo "<table width='300' border='1' cellspacing='0' cellpadding='2'
bgcolor='#FBFFC6'>";
| echo "<tr><th width='180'>Player</th><th width='40'>Won</th><th
width='40'>lost</th><th
| width='40'>Avg.</th>";
| for($i=0;$i<=$counter;$i++){
| if ($player_name[$i] != ""){
| $avg = ($player_wins[$i]/($player_wins[$i]+$player_loss[$i]));
| echo
|
"<tr><td>".$player_name[$i]."</td><td>".$player_wins[$i]."</td><td>".$player_loss[$i]."</td><td>".round($avg,3)."</td></tr>";
| }
| }
| echo "</table>";
HOLY FUCK !!! RTFM !!!!
Re: Sorting
On Fri, 23 Feb 2007 18:36:36 -0600, "Steve" <no.one [at] example.com> wrote:
><comatose> wrote in message
>news:m3uut2t6kggs59nhm6j6v0anl6bi5j77ni [at] 4ax.com...
>| Newbie here:
>| can anyone help me, i've been beating my brain on this one.
>| how can i sort from highest to lowest for $player_wins[$i] ??
>|
>|
>|
>|
>| echo "<table width='300' border='1' cellspacing='0' cellpadding='2'
>bgcolor='#FBFFC6'>";
>| echo "<tr><th width='180'>Player</th><th width='40'>Won</th><th
>width='40'>lost</th><th
>| width='40'>Avg.</th>";
>| for($i=0;$i<=$counter;$i++){
>| if ($player_name[$i] != ""){
>| $avg = ($player_wins[$i]/($player_wins[$i]+$player_loss[$i]));
>| echo
>|
>"<tr><td>".$player_name[$i]."</td><td>".$player_wins[$i]."</td><td>".$player_loss[$i]."</td><td>".round($avg,3)."</td></tr>";
>| }
>| }
>| echo "</table>";
>
>HOLY FUCK !!! RTFM !!!!
>
I did read it and Sort() doesn't work cause it throws the other arrays off or don't match up after
the sort.......why don't you try helping someone instead of being an asshole, you took the time to
write your response instead of trying to explain, that makes you an asshole.
Re: Sorting
Message-ID: <m3uut2t6kggs59nhm6j6v0anl6bi5j77ni [at] 4ax.com> from comatose
contained the following:
>Newbie here:
>can anyone help me, i've been beating my brain on this one.
>how can i sort from highest to lowest for $player_wins[$i] ??
rsort($player_wins);
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Re: Sorting
On Sat, 24 Feb 2007 01:24:37 +0000, Geoff Berrow <blthecat [at] ckdog.co.uk> wrote:
>Message-ID: <m3uut2t6kggs59nhm6j6v0anl6bi5j77ni [at] 4ax.com> from comatose
>contained the following:
>
>>Newbie here:
>>can anyone help me, i've been beating my brain on this one.
>>how can i sort from highest to lowest for $player_wins[$i] ??
>
>rsort($player_wins);
I tried rsort, although it works but just for "$player_wins" but i need to keep the association
with $player_loss and $player_name since they're directly related to each other.
from my old basic language i remembered and use a double loop to get the job done, but i know there
is a much easier way. and thats why i'm asking.
Re: Sorting
<comatose> wrote in message
news:gb4vt251aii74v7ftk349f272lhkj7foki [at] 4ax.com...
| On Fri, 23 Feb 2007 18:36:36 -0600, "Steve" <no.one [at] example.com> wrote:
|
| ><comatose> wrote in message
| >news:m3uut2t6kggs59nhm6j6v0anl6bi5j77ni [at] 4ax.com...
| >| Newbie here:
| >| can anyone help me, i've been beating my brain on this one.
| >| how can i sort from highest to lowest for $player_wins[$i] ??
| >|
| >|
| >|
| >|
| >| echo "<table width='300' border='1' cellspacing='0' cellpadding='2'
| >bgcolor='#FBFFC6'>";
| >| echo "<tr><th width='180'>Player</th><th width='40'>Won</th><th
| >width='40'>lost</th><th
| >| width='40'>Avg.</th>";
| >| for($i=0;$i<=$counter;$i++){
| >| if ($player_name[$i] != ""){
| >| $avg = ($player_wins[$i]/($player_wins[$i]+$player_loss[$i]));
| >| echo
| >|
|
>"<tr><td>".$player_name[$i]."</td><td>".$player_wins[$i]."</td><td>".$player_loss[$i]."</td><td>".round($avg,3)."</td></tr>";
| >| }
| >| }
| >| echo "</table>";
| >
| >HOLY FUCK !!! RTFM !!!!
| >
| I did read it and Sort() doesn't work cause it throws the other arrays off
or don't match up after
| the sort.......why don't you try helping someone instead of being an
asshole, you took the time to
| write your response instead of trying to explain, that makes you an
asshole.
so be it...now, reRTFM and apply some basic comprehension to the endeavor
this time.
Re: Sorting
| >rsort($player_wins);
|
|
| I tried rsort, although it works but just for "$player_wins" but i need
to keep the association
| with $player_loss and $player_name since they're directly related to each
other.
|
| from my old basic language i remembered and use a double loop to get the
job done, but i know there
| is a much easier way. and thats why i'm asking.
well, that's where actually stating the requirements helps...rather than
assuming we can read minds. why not be smarter about the whole thing and not
magically assume that $i will always point to the same data in each
variable's array? gee, how about something like:
$stats = array();
for ($i = 0; $i < count($player_names); $i++)
{
$stats[$player_names[$i]] = array(
'WINS' => $player_wins[$i] ,
'LOSES' => $player_loss[$i] ,
'AVG' => $player_wins[$i] /
(
$player_wins[$i] +
$player_loss[$i]
)
)
}
now do your sorting. if you're about to bitch cuz i didn't show you how to
sort scores here, you truly are comatose. just cuz ur new doesn't mean you
can't think! that just may be a constant condition for you regardless of
experience...but, i digress.
Re: Sorting
Message-ID: <rl7vt29dl28t39esjj81ck50qf68hon8fa [at] 4ax.com> from comatose
contained the following:
>>rsort($player_wins);
>
>
>I tried rsort, although it works but just for "$player_wins" but i need to keep the association
>with $player_loss and $player_name since they're directly related to each other.
That's not what you asked but never mind
>
>from my old basic language i remembered and use a double loop to get the job done, but i know there
>is a much easier way. and thats why i'm asking.
That sounds like a bubble sort (plenty of examples around). However you
still don't give us enough info. Where do these arrays come from? If
they come from a database then the simplest method would be to sort the
records before the output. Even if you don't use a database I still
think you can start to tackle the problem a lot further back.
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011