//另外,我如何在不使用表的情况下实现产品的4x4网格视图?提前谢谢。
<?php
include"storescripts/connect_to_mysql.php";
$sql=mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 15");
$columncount = 0;
$dynamicList = '<table align="center" width="100%" border="0" cellpadding="6"><tr>';
while($row=mysql_fetch_array($sql)){
$id=$row["id"];
$product_image = $row["product_image"];
$product_name = $row["product_name"];
$price=$row["price"];
$date_added = strftime("&b &d, &y", strtotime($row["date_added"]));
$dynamicList .= '<td width="135"><a href="product.php?id=' . $id . '">
<img src="inventory_images' . $id . '.jpg" alt="" width="129" height="169" border="0">
</a>
</td>
<td width="593" valign="bottom"></br>' . $product_name . '<br>
£' . $price . '<br>
<a href="product.php?id=' . $id . '">View Product Details</a></td>';
//缺少的表格标签是导致我的页脚在产品列表上面。这就是为什么我把它省略了
if($columncount == 3)
{
$dynamicList .= '</tr>';
$columncount = 0;
}
else
{
$columncount++;
}
}
mysql_close();
?>
这个问题更多的是关于HTML和CSS而不是PHP。但是对于不使用HTML表格的网格,你可以这样做:
echo '<div class="items">' , PHP_EOL , PHP_EOL;
$itemCount = 0;
while($itemCount < 16){
$rowOpeningHtml = null;
$rowClosingHtml = null;
if($itemCount%4 === 0) {
$rowOpeningHtml = '<div class="item-row">' . PHP_EOL;
if($itemCount > 0)
$rowClosingHtml = '</div>' . PHP_EOL . PHP_EOL;
}
echo $rowClosingHtml , $rowOpeningHtml , "'t" , '<div class="item">item' , ($itemCount + 1) , '</div>' , PHP_EOL;
++$itemCount;
}
echo '</div>' , PHP_EOL , PHP_EOL , '</div>';
并使用一些花哨的CSS样式