|
Posted by Jerry Stuckle on 09/27/94 11:37
manny wrote:
> I wish I knew what this was called, and I could have made a more sensible
> subject. For that matter, I knew what it was called, I could have googled it!
>
> Anyway, let's I have a table with name, class, grade.
>
> joe bio a
> jill chem b
> john psych b
> john chem a
> jill pysch a
>
> and I want to display the results as
>
> name bio psych chem
> joe a - -
> jill - a b
> john - b a
>
> Is there a way to do this with sql? How about sql with php?
>
> Thanks much!
>
> Manny
(Not tested)
Create an associative array (assuming you don't have two different joe's:
$result = mysql_query('SELECT name, class, grade FROM mytable');
if ($result) {
$grades = array();
while (list($name, $class, $grade) = mysql_fetch_row($result)) {
if (!exists($grades[$name])
$grades[$name] = array();
$grades[$name][$class] = $grade;
}
}
else
echo "MySQL error: " . mysql_error() . "\n";
Creates an array $grades with:
joe => (bio=>a)
jill=> (chem=>b, pysch=>a)
john=> (psych=>b, chem=>a)
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|