【发布时间】:2011-07-09 02:19:32
【问题描述】:
我的 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>
提前致谢。
-renz
【问题讨论】:
-
很可能是您的数据。您可能为相同的客户提供具有相同“日期”的服务。不过只是猜测。代码本身看起来不错。在数据库上运行查询本身,看看你得到了什么
-
@cfreak 你的权利,我在 phpmyadmin 上运行它,它是一样的。你觉得我应该怎么做?
-
修复数据完整性逻辑
标签: php mysql duplicates rows