...

View Full Version : Resolved Array - Multisort

Taylor_1978
10-29-2009, 03:07 AM
Howdy!

I've been having a little bit of a problem with this for a while now and just can't seem to work out where I've gone wrong.

Here is the code:

\$s = mysql_query("SELECT * FROM matches WHERE oldhome=\$_REQUEST[teamid] OR oldaway=\$_REQUEST[teamid] AND hforfeit=0 AND aforfeit=0 AND washout=0");
while(\$r=mfa(\$s)){
if (\$r['oldhome']==\$_REQUEST['teamid']) {
\$paid = \$r['hpaid'];
} else {
\$paid = \$r['apaid'];
}
\$paylist[] = array('Round' => \$r['round'], 'Reason' => "Fixtured Game", 'Fee' => \$gamefee, 'Credit' => 0, 'Paid' => \$paid);
}

\$s = mysql_query("SELECT * FROM team_credits WHERE tid=\$_REQUEST[teamid]");
while(\$r=mfa(\$s)){
\$paylist[] = array('Round' => \$r['round'], 'Reason' => "\$r[reason]", 'Fee' => 0, 'Credit' => \$r['amount'], 'Paid' => 0);
}
\$s = mysql_query("SELECT * FROM team_invoice WHERE tid=\$_REQUEST[teamid]");
while(\$r=mfa(\$s)){
\$paylist[] = array('Round' => \$r['round'], 'Reason' => "\$r[reason]", 'Fee' => \$r['amount'], 'Credit' => 0, 'Paid' => 0);
}

foreach (\$paylist as \$key => \$row) {
\$round[\$key] = \$row['Round'];
\$reason[\$key] = \$row['Reason'];
\$fee[\$key] = \$row['Fee'];
\$credit[\$key] = \$row['Credit'];
\$paid[\$key] = \$row['Paid'];
}
array_multisort(\$round, SORT_ASC, \$reason, SORT_ASC, \$fee, SORT_ASC, \$credit, SORT_ASC, \$paid, SORT_ASC, \$paylist);

foreach (\$paylist as \$key => \$row){
echo "Round: \$row[Round] - \$row[Reason] - \$row[Fee] - \$row[Credit] - \$row[Paid]<br/>";
}

This is the output:

[Line 1] Warning: array_multisort() [function.array-multisort]: Argument #9 is expected to be an array or a sort flag in /home/cityside/public_html/dutyreport/view.php on line 79
[Line 2] Round: 2 - Fixtured Game - 70.00 - 0 - 70
[Line 3] Round: 3 - Fixtured Game - 70.00 - 0 - 70
[Line 4] Round: 4 - Fixtured Game - 70.00 - 0 - 35
[Line 5] Round: 5 - Fixtured Game - 70.00 - 0 - 70
[Line 6] Round: 7 - Fixtured Game - 70.00 - 0 - 70
[Line 7] Round: 6 - Fixtured Game - 70.00 - 0 - 70
[Line 8] Round: 8 - Fixtured Game - 70.00 - 0 - 70
[Line 9] Round: 9 - Fixtured Game - 70.00 - 0 - 0
[Line 10] Round: 10 - Fixtured Game - 70.00 - 0 - 0
[Line 11] Round: 11 - Fixtured Game - 70.00 - 0 - 0
[Line 12] Round: 12 - Fixtured Game - 70.00 - 0 - 0
[Line 13] Round: 3 - Half Time Wet Weather - 0 - 35.00 - 0

This should simply order by Round #, that is the important thing. Based on this, Line 13 should actually be before Line 4, and for some reason Line 6 and 7 and the opposite way round (although I have a feeling this may just be due to the order it is in on the 'matches' database.

Any help much appreciated!

Taylor

Taylor_1978
10-29-2009, 03:37 AM
UGH! Can't believe I just wait almost 2 hours of my time on this... Simple solution was:

array_multisort(\$round, SORT_ASC, \$paylist);

Always the way, to post a question after working on it for hours and then solving it yourself 2 minutes later!