订单.php:
<?php
require_once('conn.php');
session_start();
$itemId=$_SESSION['itemId'];
$tnumber=$_SESSION['tnumber'];
$custno=$_SESSION['custno'];
$sql="select itemId,subtitle,price,quantity from cart where tnumber='$tnumber'" ;
$sql2="select subtitle from cart where itemId='$itemId'";
$res2=mysqli_query($dbhandle,$sql2);
$row1= mysqli_num_rows($res2);
$res=mysqli_query($dbhandle,$sql);
$total=0;
?>
<html>
<head>
<title>Home</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" type='text/css' href='cartbox.css'/>
</head>
<body>
<h1></h1>
<script src="home.js"></script>
<div id="shopping-cart"> </div>
<?php
echo "<table id='t1' border='1'>
<th>Subtitle</th>
<th>Quantity</th>
<th>Price</th>
<th>Amount</th>
</tr>";
if (row1 > 0) {
while ($row=mysqli_fetch_array($res)) {
$amount=$row['price']*$row['quantity'];
echo "<form id='addform{$row['itemId']}' method='post' action='cartdelete.php'> ";
echo "<tr>";
echo "<td>" .$row['subtitle'] ."</td>";
echo "<td>" .$row['quantity'] ."</td>";
echo "<td>" .$row['price'] ."</td>";
echo "<td>" . $amount . "</td>";
echo "<td><input type='submit' value='x' name='submit'></td>";
echo "<td><input type='text' name='itemId' value= '{$row['itemId']}'></td>";
echo"</form>";
echo "</tr>";
$total = $total+ $amount;
}
}
echo "</table>";
?>
<?php echo $total ?>
<input type="button" name="continue" value="Continue Order" style="position: absolute;top:200px;" onclick="location.href='customerdicecream.php'">
</body>
</html>
我正在尝试在 HTML 表中显示数据(使用主键)。我只需要将字幕输入到 HTML 表中一次,但是在 if
条件下我无法实现它。我该怎么做?
最佳答案
您可以在查询中使用 DISTINCT
/GROUP BY
来防止冗余值。
例如。
$sql="select itemId,subtitle,price,quantity from cart where tnumber='$tnumber'" ;
$sql2="select DISTINCT subtitle from cart where itemId='$itemId'";
关于php - 如何避免在 html 表中打印重复值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23125942/