gpt4 book ai didi

php/MySQL - 如何将产品表连接在一起

转载 作者:行者123 更新时间:2023-11-29 23:15:14 26 4
gpt4 key购买 nike

如何将该表合并为 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 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 '&pound'.number_format($get_row['price'],2).'<br><br> <a href="cart.php?add='.$get_row['id'].'">Add</a></p>';?>
</td>
</tr>
</table></center>

<?}

}


}

当前显示:

enter image description here

但理想情况下,我不喜欢每个项目的标题!

最佳答案

您在 while 循环中调用表和表头。所以,出于这个原因输出。尝试这个改变

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 {
echo "<center>\n";
echo " <table border=2 width=90% 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 '&pound'.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";
}
}

关于php/MySQL - 如何将产品表连接在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27872960/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com