?
2012-08-12 13:52:50 UTC
The data of "posts" is as follow.
id sender_id post_type text date
1 2 t hi Saturday, 4th August 2012, 7:43:18 pm
3 1 t hello Tuesday, 7th August 2012, 4:39:31 am
4 1 t how r u? Tuesday, 7th August 2012, 4:39:39 am
5 1 t thats cool Tuesday, 7th August 2012, 7:49:35 am
6 1 t good Tuesday, 7th August 2012, 7:49:45 am
7 2 t fine Tuesday, 7th August 2012, 7:50:05 am
8 2 t great Tuesday, 7th August 2012, 7:50:08 am
There is another table named "subscription".
The data of "subcription" is as follow.
id subscriber subscribed date
1 3 1 Friday, 6th July 2012, 7:25:41 pm
2 4 1 Saturday, 7th July 2012, 4:38:26 pm
3 4 2 Sunday, 8th July 2012, 6:46:52 pm
Now I want to fetch row from posts table if "sender_id" of "posts" table is in "subscribed" column
of "subscription" table WHERE "subscriber" = URL id.
I am using this code for it.
$post_query = mysql_query(" SELECT posts.*, subscription.* FROM posts
INNER JOIN subscription ON subscription.subscriber = $uid
ORDER BY posts.id DESC ") or mysql_error();
while($post_row = mysql_fetch_array($post_query))
{
echo $post_text = $post_row['text'].'
';
}
Now when URL id = 3
( http://localhost/userarea.php?id=3 )
then it shows the result like
hello
great
fine
good
thats cool
how r u?
hello
hi
( Remember that did not subscribe any other id and I want to show post by only id or ids who are
subscribed by id 3 )
And when URL id = 4
( http://localhost/userarea.php?id=4 )
then it shows the result like
hello
hello
great
great
fine
fine
good
good
thats cool
thats cool
how r u?
how r u?
hello
hello
hi
hi
It duplicate the results.
Remember that id 3 subscribed one user only and id 4 subscribed two users.
I know something is wrong with my INNER JOIN query.
Please tell me the correct way to write this.
Thanks.