I cant get the script below to work properly. I want it to
sort the output when I click on each of the column headings,
but the script doesnt output the array properly. Can anybody help me with this ?
<?
if (!isset($_GET['sort_array'])) {
$sort_key = 'Firstname';
}
else {
$sort_key = urldecode($_GET['sort_array']);
}
$head = array('Firstname', 'Lastname', 'Tlf');
$info = array(
array('Thor', 'Watson', '97223344'),
array('Penny', 'Parker', '93426252'),
array('Johnny', 'Sanders', '92442213'),
array('Maria', 'Hansen', '92442213'),
array('Mona', 'Andersen', '92442213')
);
foreach ($info as $key => $line) {
$items = explode(';', $line);
$i = 0;
foreach ($items as $item) {
$tmp[$key][$head[$i++]] = trim($item);
}
}
foreach ($tmp as $key => $line) {
$tmp2[] = $line[$sort_key];
}
array_multisort($tmp2, SORT_DESC, $tmp);
echo "<table border=1>";
echo "<tr>";
foreach ($head as $part) {
echo "<td bgcolor=lightgrey><a class=cd href=".$_SERVER['PHP_SELF']."?sort_array=".urlencode($part).">".$part."</a></td>";
}
echo "</tr>";
foreach ($tmp as $value) {
echo "<tr>";
foreach ($value as $something) {
echo "<td class=nav2>" . $something . "</td>";
}
echo "</tr>";
}
echo "</table>";
?>