如何防止该查询两次打印相同的结果? [英] How to prevent this query from printing same results twice?

查看:86
本文介绍了如何防止该查询两次打印相同的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法创建了适合我需要的查询.但是现在我遇到了一个问题,在给定当前显示结果的方式的情况下,查询将每个结果重复两次.我如何才能使其在一次显示的地方正确工作.

I managed to create a query that fit my need. But now I am running into issues where given the current way of displaying results the query repeats each and every result twice. How can i make it work correctly where it shows it once.

代码:

$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");
}

}

推荐答案

而不是使用mysql_fetch_array(),请使用

Instead of using mysql_fetch_array() use mysql_fetch_assoc(). By default, mysql_fetch_array() will return an array with both associative and number indices which will result in you seeing the results twice.

这篇关于如何防止该查询两次打印相同的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆