我正在开发一个小订单购物车,目前我已经实施了MySQL来显示数据库中的产品。我希望这些产品能够拥有自己的图像,并将其组织成3个独立的桌子,用于开胃菜,主菜和甜点。
目前,我有一个包含所有商品的表格,我不确定如何在所选商品旁边添加图片。
这里显示:
这是我的代码:
<?php
session_start();
$page = 'index.php';
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('cart') or die(mysql_error());
if (isset($_GET['add'])) {
$quantity = mysql_query('SELECT id, quantity FROM products WHERE id='.mysql_real_escape_string((int)$_GET['add']));
while ($quantity_row = mysql_fetch_assoc($quantity)) {
if ($quantity_row['quantity']!=$_SESSION['cart_'.(int)$_GET['add']]) {
$_SESSION['cart_' . (int)$_GET['add']] +='1';
header('Location: ' . $page);
}
}
header('Location: ' . $page);
}
if (isset($_GET['remove'])) {
$_SESSION['cart_'.(int)$_GET['remove']]--;
header ('Location: ' . $page);
}
if (isset($_GET['delete'])) {
$_SESSION['cart_' . (int)$_GET['delete']]='0';
header ('Location: ' . $page);
}
function products() {
$get = mysql_query('SELECT id, name, description, price FROM products WHERE quantity > 0 ORDER BY id ASC');
if (mysql_num_rows($get) == 0) {
echo "There are no products to display.";
}
else {
echo "<center>\n";
echo " <table border=2 width=40% cellspacing=5 cellpadding=10 bgcolor=cyan cols=2>\n";
echo " <tr>\n";
echo " <th>View</th>\n";
echo " <th>Dish</th>\n";
echo " <th>Description</th>\n";
echo " <th>Item Price</th>\n";
echo " </tr>\n";
while ($get_row = mysql_fetch_assoc($get)) {
?>
<tr>
<td> <a href="ice.png"</a> </td>
<td> <?echo '<p>'.$get_row['name']?> </td>
<td> <?echo $get_row['description']?> </td>
<td> <?echo '£'.number_format($get_row['price'],2).'<br><br> <a href="cart.php?add='.$get_row['id'].'">Add</a></p>';?> </td>
</tr>
<?
}
echo "</table>\n";
echo "</center>\n";
}
}
答案 0 :(得分:0)
您可以向具有产品类型的表添加字段。
因此,您将能够使用条件执行3个单独的查询。
例如"SELECT id, name, description, price FROM products WHERE quantity > 0 AND type LIKE 'desert' ORDER BY id ASC"
等等