我的 fetch_assoc 返回重复的行。似乎它自己倍增。我的表中有 4 个输入,它返回 16 个。
这是我的代码....请帮助我。我想我循环错了。
<?php
$tryshow =" SELECT c.customer_date, c.lastname, c.firstname,
s.room_number, s.date_in, s.date_out
FROM customers c
INNER JOIN services s
ON c.customer_date = s.date_in
WHERE c.customer_date = '$customer_date' ";
$result = @mysql_query($tryshow,$conn)
or die(mysql_error());
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print...";
}
?>
<form>
<table width="700" border="0">
<tr>
<td width="100">Customer Date:</td>
<td width="100">Last Name</td>
<td width="100">First Name</td>
<td width="100">Room Number</td>
<td width="100">Date In</td>
<td width="100">Date Out</td>
</tr>
<?php while($row=mysql_fetch_assoc($result)){ ?>
<tr>
<td><?php echo $row['customer_date']; ?></td>
<td><?php echo $row['lastname']; ?></td>
<td><?php echo $row['firstname']; ?></td>
<td><?php echo $row['room_number']; ?></td>
<td><?php echo $row['date_in']; ?></td>
<td><?php echo $row['date_out']; ?></td>
</tr>
<?php }?>
</table>
提前致谢。
-伦茨
最佳答案
如果查询在 phpMyAdmin 中运行相同,您有两种选择。首先,您可以清理数据。如果可能的话,这是最好的方向。更好的数据使更好的应用成为可能。如果您不能为数据完整性做很多事情,那么您需要考虑它。最简单的方法是在您的查询中添加一个不同的....
SELECT distinct c.customer_date, c.lastname, c.firstname,
s.room_number, s.date_in, s.date_out
FROM customers c
INNER JOIN services s
ON c.customer_date = s.date_in
WHERE c.customer_date = '$customer_date'
关于php - mysql_fetch_assoc 返回重复的行...,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5198738/