Php 如何防止此查询两次打印相同的结果?
我设法创建了一个符合我需要的查询。但现在我遇到了这样的问题:给定当前显示结果的方式,查询会将每个结果重复两次。如何使它在显示一次的位置正确工作 代码:Php 如何防止此查询两次打印相同的结果?,php,mysql,sql,repeat,Php,Mysql,Sql,Repeat,我设法创建了一个符合我需要的查询。但现在我遇到了这样的问题:给定当前显示结果的方式,查询会将每个结果重复两次。如何使它在显示一次的位置正确工作 代码: $sql = "SELECT DISTINCT contacts.contact_id, user_accounts.full_name, contact_notes.note_name, contact_notes.type, contact_notes.note_id, contact_posts.why_post, contact_po
$sql = "SELECT DISTINCT contacts.contact_id, user_accounts.full_name,
contact_notes.note_name, contact_notes.type, contact_notes.note_id,
contact_posts.why_post, contact_posts.type, contact_posts.post_id
FROM contacts, user_accounts, contact_notes, contact_posts
WHERE (contacts.system_id = '$sid' AND contacts.contact_id =
user_accounts.system_id AND contact_notes.user_allowed = '$everybody' AND
contact_posts.user_allowed = '$everybody') OR (contacts.contact_id = '$sid'
AND contacts.system_id = user_accounts.system_id AND contact_notes.user_allowed
= '$everybody' AND contact_posts.user_allowed = '$everybody')
LIMIT $startrow, 20";
$query = mysql_query($sql) or die ("Error: ".mysql_error());
$result = mysql_query($sql);
if ($result == "")
{
echo "";
}
echo "";
$rows = mysql_num_rows($result);
if($rows == 0)
{
print("");
}
elseif($rows > 0)
{
while($row = mysql_fetch_array($query))
{
$noteid = htmlspecialchars($row['note_id']);
$note_title = htmlspecialchars($row['note_name']);
$postid = htmlspecialchars($row['post_id']);
$postreason = htmlspecialchars($row['why_post']);
$datetimeadded = htmlspecialchars($row['just_date']);
print("<br /> <br />$note_title - $noteid <br /><br />$postreason - $postid");
}
}
$sql=“选择不同的联系人。联系人id,用户帐户。全名,
联系人\u notes.note\u姓名、联系人\u notes.type、联系人\u notes.note\u id、,
contact_posts.why_post,contact_posts.type,contact_posts.post_id
来自联系人、用户帐户、联系人备注、联系人帖子
其中(contacts.system_id='$sid'和contacts.contact_id=
user_accounts.system_id和contact_notes.user_allowed='$Everyone'和
contact_posts.user_allowed='$everybody')或(contacts.contact_id='$sid'
和contacts.system\u id=允许的用户\u帐户.system\u id和联系人\u notes.user\u
='$Everyone'和联系人_posts.user_allowed='$Everyone')
限制$startrow,20”;
$query=mysql\u query($sql)或die(“错误:.mysql\u Error());
$result=mysql\u查询($sql);
如果($result==“”)
{
回声“;
}
回声“;
$rows=mysql\u num\u rows($result);
如果($rows==0)
{
打印(“”);
}
elseif($rows>0)
{
while($row=mysql\u fetch\u array($query))
{
$noteid=htmlspecialchars($row['note_id']);
$note_title=htmlspecialchars($row['note_name']);
$postid=htmlspecialchars($row['post_id']);
$postreason=htmlspecialchars($row['why_post']);
$datetimeadded=htmlspecialchars($row['just_date']);
打印(“
$note\u title-$noteid
$postreason-$postid”);
}
}
而不是使用mysql\u fetch\u array()
使用。默认情况下,mysql\u fetch\u array()
将返回一个包含关联索引和数字索引的数组,这将导致您看到两次结果。嘿,这仍然会重复查询两次。嘿,我仍然需要一些帮助。使用mysql_fetch_assoc()我也遇到了同样的问题。