How could I fetch a specific record only and if a condition is met?
I have the code as
"SELECT a.id, a.text, a.uid, a.time
FROM story a INNER JOIN friends b
ON ((a.uid = '" . $uid . "') OR
(b.uid = '" . $uid . "' AND accepted='1') OR
(b.fid = '" . $uid . "' AND accepted='1'))
ORDER BY a.time DESC
LIMIT 3";
It works fine except that when the friends table is empty, it will not show the story records.
what i want to achieve is
-
if the uid in table story is equal to logged in uid (user), then show the text from table story (meaning it is his own story)
-
if the uid in table story is equal to uid in table friends and its friendship is accepted OR if the uid in table story is equal to fid in table friends and its friendship is accepted then show the text in table story (meaning the story is from a friend and its shown only if friendship is accepted)
-
if there is no friendships at all, just show own stories from table story and omit others
I think you are not using proper join format. It should be as :
You can check the basics here.
In your case you should write query as following:
I think it will help.