tags:

views:

93

answers:

1

i am trying to develop a site where users can become friends of each other and can see their posts after the date the became friends........i have already posted this question about 5-7 days but could not find any solution........!! so... i have two tables.......... posts and friends and my query is

$sql = mysql_query("
SELECT * 
FROM posts p 
JOIN friends f 
ON p.currentuserid = f.friendid 
AND p.time >= f.friend_since 
OR s.currentuserid=$myid 
WHERE f.myid=$thisid 
ORDER BY p.postid DESC LIMIT 20");

where $myid is currentuserid and p.currentuserid is the name of cell in poss table and friendid is in friends table.

this query is working all the way right but problem is that in this query if current user post any thing it displays two times i.e

my new post
mynew post

but in database it is single entry.....!! but current user can see their friends posts for single time

how can i solve this problem

+2  A: 

this query is working all the way right but problem is that in this query if current user post any thing it displays two times

Use:

SELECT DISTINCT * 
  FROM posts p 
  JOIN friends f ON p.currentuserid = f.friendid 
                AND p.time >= f.friend_since 
                 OR s.currentuserid=$myid 
 WHERE f.myid=$thisid 
ORDER BY p.postid DESC 
   LIMIT 20

I added the DISTINCT keyword in order to remove duplicates. Usually I'd use a GROUP BY instead, but you didn't supply the columns.

OMG Ponies
it is working fine in chrome but in ff and ie it is still showing duplicates
Web Worm
That's a browser caching issue, nothing to do with a SQL query.
OMG Ponies