[solved] how to sort an array?
Posted: Tue Aug 29, 2006 7:55 pm
Hi all, I have a bunch of data in an array. This first code example is inside another loop. During the loop I place the data into the array like so:
When $counter reaches 0 the array stops and all the data has been put in the array. We then have everything we need to draw the info and I do so like this:
That all works a treat, but unfortunately it draws each client, their total transactions, the amount they spent and GST... in the order they are in the array.
I want to be able to sort the array dynamically (via postdata say) where I let the user choose to sort by either name, transactions, or more importantly, how much each client has spent.
This is a LONG post to ask a simple question
The question is, how can I sort this array?
Any advice is GREATLY appreciated.
Rob
Code: Select all
if ($counter > 0)
{
//now stick this stuff into an array
$trans_draw_multi_array[] = array($client_name_data_array[id], $client_full_name, $counter, $price_sub);
}Code: Select all
foreach($trans_draw_multi_array as $draw)
{
//work out the totals and whatnot
$price_total = ($draw[3] + $price_total);
$gst = ($draw[3] * $cfg_gst_rate);
$gst = round($gst, 2);
$gst_total = ($gst_total + $gst);
$gst_total = round($gst_total);
//draw the actual number and description
echo "<td align = \"left\" class = \"\" width = \"65%\">$draw[1]</td><td align = \"left\" class = \"\">$draw[2] sold</td><td align = \"left\" class = \"\">$$draw[3]<br>";
if ($gst_checked == "1")
{
echo "<td align = \"left\" class = \"\">$$gst</td>";
}
else
{
echo "<td align = \"left\" class = \"\"></td>";
}
}
//draw the total
//===============
echo "<tr><td align = \"left\" class = \"history_dark_medium_01\" width = \"70%\">Total Transactions</td><td align = \"left\" class = \"history_dark_medium_01\">$counter_total sold</td><td align = \"left\" class = \"history_dark_medium_01\">$$price_total</td>";
if ($gst_checked == "1")
{
echo "<td align = \"left\" class = \"history_dark_medium_01\">$$gst_total</td></tr>";
}
else
{
echo "<td align = \"left\" class = \"history_dark_medium_01\"></td></tr>";
}
echo "</table>";I want to be able to sort the array dynamically (via postdata say) where I let the user choose to sort by either name, transactions, or more importantly, how much each client has spent.
This is a LONG post to ask a simple question
Code: Select all
$trans_draw_multi_array[]Rob