Hello. Someone on this forum helped me with the following script, and im really greatfull. Now I would like to take it a
bit further.
I wonder if anybody could help me with the following :
Im trying to get the description (Food, Water, Eatable, etc..)
of the sorted column highlighted with bold text.
In other words. If i sort the column Fat, I want description Fat
to be printed out in bold text, and the other columns as
normal. Likewise for the other columns when I sort them.
Here is the script :
<b>Food Nutrient Content Table</b></p>
<?
if (!isset($_GET['sorting'])) {
$sort_key = 'Food';
}
else {
$sort_key = urldecode($_GET['sorting']);
}
$d = array('Food','Eatable(%)','Water(g)','Energy(kj)','Protein(g)','Fat(g)','Carbohydrates(g)','Fibre(g)',
'Sugar(g)','Iron(mg)','Vitamin A(mg)','Vitamin C(mg)','Vitamin D(mg)','Vitamin E(mg)');
$file = file("food_nutrient_content_table.txt");
foreach ($file as $key => $line) {
$items = explode(';', $line);
$i = 0;
foreach ($items as $item) {
$tmp[$key][$d[$i++]] = trim($item);
}
}
foreach ($tmp as $key => $line) {
$tmp2[] = $line[$sort_key];
}
array_multisort($tmp2, SORT_DESC, $tmp);
echo "<table>";
echo "<tr>";
foreach ($d as $desc) {
echo "<td class=s><a class=cd href=".$_SERVER['PHP_SELF']."?sorting=".urlencode($desc).">".$desc."</a></td>";
}
echo "</tr>";
foreach ($tmp as $value) {
echo "<tr>";
foreach ($value as $something) {
if(ereg('Food|Eatable|Water|Energy|Protein|Fat|Carbo|Fibre|Sugar|Iron|VitA|VitC|VitD|VitE',$something)) {} else {
echo "<td class=nav4>" . $something . "</td>";
}
}
echo "</tr>";
}
echo "</table>";
?>