我的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