如何將此表連接成3個部分?一個用於初學者,主菜和甜點。php/MySQL - 如何將產品表連接在一起
這裏是我到目前爲止的代碼:
<?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 DESC');
if (mysql_num_rows($get) == 0) {
echo "There are no products to display.";
}
else {
while ($get_row = mysql_fetch_assoc($get)) {?>
<center>
<table border=2 width=90% cellspacing=5 cellpadding=10 bgcolor=cyan cols=2>
<th>View</th>
<th>Dish</th>
<th>Description</th>
<th>Item Price</th>
<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>
</table></center>
<?}
}
}
這當前顯示:
但最好我不喜歡的標題爲每對項目!
是不是簡單的HTML? (而不是所有這些標籤)? –