我按照在线教程创建了一个管理后端,最后在 php 页面的 HTML 标记之前得到了这段代码:
<?php
$product_list = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0)
{
while($row = mysql_fetch_array($sql))
{
$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$product_list .= "Product ID: $id - <strong>$product_name</strong> - $$price - <em>Added $date_added</em> <a href='inventory_edit.php?pid=$id'>edit</a> • <a href='inventory_list.php?deleteid=$id'>delete</a><br />";
}
}
else
{
$product_list = "You have no products listed in your store yet";
}
?>
当我将<?php echo $product_list; ?>
页面内容放在页面上时,我会检索到这样的列表结果:
Product ID: 1 - Strawberries - $10 - Added Mar 22, 2013 edit • delete
Product ID: 2 - Apples 1 - $10 - Added Mar 22, 2013 edit • delete
我想要的是把它放在一个对称的列表视图中,就像一个表格一样,以呈现结果和编辑/删除选项。试图放置一张 1 行 5 列的表格,$product_list
但没有成功。