2012-05-12 8 views
0

私のニーズに合ったクエリを作成することができました。しかし、今私は、問合せがそれぞれの結果とすべての結果を2回繰り返す結果を表示する現行の方法を考慮して、問題に取り組んでいます。一度それが示されているところで、どうすれば正しく動作させることができますか?このクエリで同じ結果が2回印刷されないようにするにはどうすればよいですか?

コード:

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

} 

答えて

2

代わりmysql_fetch_array()使用mysql_fetch_assoc()を使用します。デフォルトでは、mysql_fetch_array()は、アソシエーティブの両方のインデックスを持つ配列を返します。これにより結果が2回表示されます。

+0

ちょっと、クエリを2回繰り返しています。 – ariel

+0

ねえ、まだ助けが必要です。 mysql_fetch_assoc()で同じ問題が発生しています。 – ariel

関連する問題