Code generated column sort
Posted: Wed Mar 01, 2006 5:15 am
feyd | Please use
Is it possible to order (highest to lowest) the rows using a PHP sort function like arsort?
If so how does that function fit into the code structure above and what is the correct syntax. I'm having trouble finding useful examples of this beyond the very basic intro in the PHP manual.
Thanks
David
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
I wish to display a series of rows in a table, ordered by the column 'order total'. 'order total' is calculated in PHP rather than being available as a database field, therefore I can't use the 'order by' option in my query.
The code I'm using to display the table rows is:Code: Select all
$userPoints = array();
while ($row = mysql_fetch_assoc($result)) {
$userPoints[$row["username"]][$row["round"]] = $row["points"];
}
foreach($userPoints as $username => $rounds) {
echo "<tr>";
echo "<td>".$username."</td>";
$total = 0;
for($i = 1; $i < 27; $i++) {
echo "<td>".($rounds[$i] ? $rounds[$i] : "-")."</td>";
$total += $rounds[$i];
}
echo "<td><strong>".$total."</strong></td>";
echo "</tr>";
}If so how does that function fit into the code structure above and what is the correct syntax. I'm having trouble finding useful examples of this beyond the very basic intro in the PHP manual.
Thanks
David
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]