PHP ver gevorderde |
|
Dit bedoel jij . Heb het al getest en het werkt precies zoals jij wilt .
Edit: Even ervoor gezorgd dat als het aantal rijen geen even getal vormt dat je dan wel die laatste rij ook nog moet kunnen zien.
<?php
$rRows = mysql_query('SELECT name, picture, price, stock FROM products ORDER BY id LIMIT 7, 12');
$iCounter = $iColor = 0;
// De kleuren die de rijen krijgen.
$aColorTable = array
(
array('#fcc', '#f0c'),
array('#f0c', '#fcc')
);
// Slaat telkens 2 rijen op.
$aRows = array();
echo '<table>';
while (($aRow = mysql_fetch_assoc($rRows)) !== false)
{
$aRows[] = $aRow;
if (count($aRows) == 2)
{
// We laten de kleur varieren per 2 mysql rijen
$iColorKey = ($iColor++ % 2 == 0) ? 0 : 1;
echo '<tr>';
echo '<td style="background-color: '.$aColorTable[$iColorKey][0].'"><span style="color: #090708;">'.$aRows[0]['name'].'</span></td>';
echo '<td style="background-color: '.$aColorTable[$iColorKey][1].'"><span style="color: #090708;">'.$aRows[1]['name'].'</span></td>';
echo '</tr>';
echo '<tr>';
echo '<td style="background-color: '.$aColorTable[$iColorKey][0].'"><img src="products/thumb_'.$aRows[0]['picture'].'" alt="'.$aRows[0]['name'].'" /></td>';
echo '<td style="background-color: '.$aColorTable[$iColorKey][1].'"><img src="products/thumb_'.$aRows[1]['picture'].'" alt="'.$aRows[1]['name'].'" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td style="background-color: '.$aColorTable[$iColorKey][0].'">€ '.$aRows[0]['price'].'</td>';
echo '<td style="background-color: '.$aColorTable[$iColorKey][1].'">€ '.$aRows[1]['price'].'</td>';
echo '</tr>';
echo '<tr>';
echo '<td style="background-color: '.$aColorTable[$iColorKey][0].'">Nog in voorraad: '.$aRows[0]['stock'].'</td>';
echo '<td style="background-color: '.$aColorTable[$iColorKey][1].'">Nog in voorraad: '.$aRows[1]['stock'].'</td>';
echo '</tr>';
$aRows = array();
}
}
if (count($aRows) == 1)
{
$iColorKey = ($iColor++ % 2 == 0) ? 0 : 1;
echo '<tr>';
echo '<td style="background-color: '.$aColorTable[$iColorKey][0].'"><span style="color: #090708;">'.$aRows[0]['name'].'</span></td>';
echo '</tr>';
echo '<tr>';
echo '<td style="background-color: '.$aColorTable[$iColorKey][0].'"><img src="products/thumb_'.$aRows[0]['picture'].'" alt="'.$aRows[0]['name'].'" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td style="background-color: '.$aColorTable[$iColorKey][0].'">€ '.$aRows[0]['price'].'</td>';
echo '</tr>';
echo '<tr>';
echo '<td style="background-color: '.$aColorTable[$iColorKey][0].'">Nog in voorraad: '.$aRows[0]['stock'].'</td>';
echo '</tr>';
}
echo '</table>';
?>
<?php $rRows = mysql_query('SELECT name, picture, price, stock FROM products ORDER BY id LIMIT 7, 12'); $iCounter = $iColor = 0; // De kleuren die de rijen krijgen. ( ); // Slaat telkens 2 rijen op. { $aRows[] = $aRow; { // We laten de kleur varieren per 2 mysql rijen $iColorKey = ($iColor++ % 2 == 0) ? 0 : 1; echo '<td style="background-color: '.$aColorTable[$iColorKey][0].'"><span style="color: #090708;">'.$aRows[0]['name'].'</span></td>'; echo '<td style="background-color: '.$aColorTable[$iColorKey][1].'"><span style="color: #090708;">'.$aRows[1]['name'].'</span></td>'; echo '<td style="background-color: '.$aColorTable[$iColorKey][0].'"><img src="products/thumb_'.$aRows[0]['picture'].'" alt="'.$aRows[0]['name'].'" /></td>'; echo '<td style="background-color: '.$aColorTable[$iColorKey][1].'"><img src="products/thumb_'.$aRows[1]['picture'].'" alt="'.$aRows[1]['name'].'" /></td>'; echo '<td style="background-color: '.$aColorTable[$iColorKey][0].'">€ '.$aRows[0]['price'].'</td>'; echo '<td style="background-color: '.$aColorTable[$iColorKey][1].'">€ '.$aRows[1]['price'].'</td>'; echo '<td style="background-color: '.$aColorTable[$iColorKey][0].'">Nog in voorraad: '.$aRows[0]['stock'].'</td>'; echo '<td style="background-color: '.$aColorTable[$iColorKey][1].'">Nog in voorraad: '.$aRows[1]['stock'].'</td>'; } } { $iColorKey = ($iColor++ % 2 == 0) ? 0 : 1; echo '<td style="background-color: '.$aColorTable[$iColorKey][0].'"><span style="color: #090708;">'.$aRows[0]['name'].'</span></td>'; echo '<td style="background-color: '.$aColorTable[$iColorKey][0].'"><img src="products/thumb_'.$aRows[0]['picture'].'" alt="'.$aRows[0]['name'].'" /></td>'; echo '<td style="background-color: '.$aColorTable[$iColorKey][0].'">€ '.$aRows[0]['price'].'</td>'; echo '<td style="background-color: '.$aColorTable[$iColorKey][0].'">Nog in voorraad: '.$aRows[0]['stock'].'</td>'; } ?>
|