Voor mijn voorraad wens ik de matenbalk horizontaal te halen uit de tabel.
Mijn tabel is als volgt :
ID Voorraad_ID Matenbalk Maat Aantal
1 1 1 S 1
2 1 1 M 2
3 1 1 L NULL
4 2 2 38 1
5 2 2 40 NULL
6 2 2 44 1
Mijn code is de volgende :
<?php
$qry = mysql_query( "SELECT * FROM voorraad_maten ORDER By Matenbalk, ID asc" );
$qryMinMax = mysql_query( "SELECT MIN(Voorraad_ID) as 'Min', MAX(Voorraad_ID) as 'Max' From voorraad_maten" );
$rowMax = mysql_fetch_array( $qryMinMax );
$max = $rowMax[ 'Max' ];
$min = $rowMax[ 'Min' ];
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Naamloos document</title>
</head>
<body>
<?php
echo "<table border='solid 1px' width=75%>";
for ( $i = $min; $i <= $max; $i++ ) {
echo "<tr>";
echo "<td align='center'> Balk-" . $i . "</td>";
while ( ( ( $row = mysql_fetch_array( $qry ) )and( $row[ 'Voorraad_ID' ] ) == $i ) ) {
if ( ( is_null( $row[ 'Aantal' ] ) ) ) {
$quant = 0;
} else {
$quant = $row[ 'Aantal' ];
}
echo "<th align='center'>" . $row[ 'Maat' ] . "</th>";
echo "<td align='center'>" . $quant . "</td>";
}
}
echo "</tr>";
echo "</table>";
?>
</table>
</body>
</html>
Het resultaat is niet in orde omdat ik graag het als volg had :
Balk 1 - S M L
1 2 0
Balk 2 - 38 40 44
1 0 1
Maar maat 38 valt weg en het aantal komt langs de maat ipv onder de maat.
Graag hulp aub...
2.900 views