This code will convert (pivot) your MySQL database table from rows to columns. Here is an example of what this code will do:
Original Table | ||
ID | Name | Color |
1 | James | Blue |
2 | Amy | Red |
Converted Table | ||
ID | 1 | 2 |
Name | James | Amy |
Color | Blue | Red |
n";
$records = array();
while(($row = mysql_fetch_assoc($result))) {
$records[]=$row;
}
foreach($records as $key => $row) {
foreach($row as $field => $value) {
$recNew[$field][] = $value;
}
}
foreach ($recNew as $key => $values)
{
echo "
echo "t
n";
foreach ($values as $cell)
{
echo "t
n";
}
echo "
n"; // end row
}
echo "
";
?>