I have to write a simple script to obtain the results from a MySql dbase and put the data in table. B/c I am new to PHP,I was wondering if anyone has a simplier way to do it then how I did ('a' can be in the table up to 3 times - once with an entry for 'b', once with an entry for 'c', and once with an entry for 'd':
$data = array();
while($r = mysql_fetch_array($result)) {
$a = $r[0]; $y = $r[1];
// create new entry for the given college
if( !isset($data[$a]) ) {
$data[$a] = array();
$data[$a]["a"] = $a;
$data[$a]["b"] = "n/a";
$data[$a]["c"] = "n/a";
$data[$a]["d"] = "n/a";
}
$data[$a][$y] = $r[2];
}
sort($data);
foreach( $data as $x ) {
echo("<tr>\n");
echo(" <td>" . $x["a"] . "</td>\n");
echo(" <td>" . $x["b"] . "</td>\n");
echo(" <td>" . $x["c"] . "</td>\n");
echo(" <td>" . $x["d"] . "</td>\n");
echo("</tr>\n");
}