佈局是塊/模塊化的,所以我需要爲每個div應用一個類。問題是,當我在瀏覽器中預覽,代碼循環開始再次在情況1之後 - 它跳過從DB的項目之一,並顯示下一個項目的情況下,1使用switch語句從數據庫調用:PHP
$result = mysqli_query($connection, "SELECT * FROM products");
$index = 1;
while($row = mysqli_fetch_array($result)) {
$float = "";
switch ($index) {
case 1: $float = "large-left";
echo "<div class=\"$float\"><img src=\"" . $row['product_imagepath'] . "\"/></div>";
break;
case 2: $float = "mini-left";
echo "<div class=\"$float\"><img src=\"" . $row['product_imagepath'] . "\"/></div>";
break;
case 3: $float = "mini-right";
echo "<div class=\"$float\"><img src=\"" . $row['product_imagepath'] . "\"/></div>";
break;
case 4: $float = "mini-left";
echo "<div class=\"$float\"><img src=\"" . $row['product_imagepath'] . "\"/></div>";
break;
case 5: $float = "mini-right";
echo "<div class=\"$float\"><img src=\"" . $row['product_imagepath'] . "\"/></div>";
break;
case 6: $float = "large-right";
echo "<div class=\"$float\"><img src=\"" . $row['product_imagepath'] . "\"/></div>";
break;
case 7: $float = "mini-left";
echo "<div class=\"$float\"><img src=\"" . $row['product_imagepath'] . "\"/></div>";
break;
case 8: $float = "mini-right";
echo "<div class=\"$float\"><img src=\"" . $row['product_imagepath'] . "\"/></div>";
break;
case 9: $float = "mini-left";
echo "<div class=\"$float\"><img src=\"" . $row['product_imagepath'] . "\"/></div>";
break;
case 10: $float = "mini-right";
echo "<div class=\"$float\"><img src=\"" . $row['product_imagepath'] . "\"/></div>";
break;
default: $index = 0;
break;
};
$index++;
};
mysqli_close($result);
?>
任何建議/替代方法將不勝感激!
「分組」請告訴我這裏$指數是爲了什麼? – Naincy 2014-08-29 06:43:21