我第一次遇到这种奇怪的情况,并且考虑到我在 PHP 中的新状态,它更加令人困惑。在下面的查询中,“asked by”一词的重复次数超出了应有的次数。它重复的次数与我猜它不应该显示的条目数量有关。
代码:
$sql = "SELECT DISTINCT
allowed_permissions.post_id,
client_visit.client_reason,
accounts.full_name,
client_visit.type
from allowed_permissions
LEFT JOIN
client_visit
on allowed_permissions.post_id = client_visit.visit_id
LEFT JOIN
accounts
ON client_visit.system_id = accounts.system_id
where
allowed_permissions.allowed_to_view = '$uid'";
$result = mysql_query($sql);
$query = mysql_query($sql) or die ("Error: ".mysql_error());
if ($result == "") {
echo "";
}
echo "";
$rows = mysql_num_rows($result);
if($rows == 0) {
} elseif($rows > 0) {
while($row = mysql_fetch_assoc($query)) {
$reason = $row['client_reason'];
$person = $row['full_name'];
//Here the asked word gets repeated...
echo"$reason asked by $person";
}
}