我的fetch_assoc返回重复的行。它似乎在自我繁殖。我有4个输入在我的表中,它返回16.mysql_fetch_assoc返回重复的行...
这是我的代码....请帮助我。我认为我的循环错误。
<?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 2011-03-04 20:13:27
@cfreak你的权利我运行它在phpmyadmin和它一样。你认为我应该怎么做? – renz 2011-03-04 20:19:10
修复您的数据完整性逻辑 – 2011-03-04 20:24:26