Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SELECT * FROM tblPosts WHERE tblPosts.usersID = (SELECT tblFriends.friendsID WHERE tblFriends.myID = '$myID') ORDER BY tblPosts.date DESC;

SELECT * FROM tblPosts WHERE tblPosts.usersID = (SELECT tblFriends.friendsID WHERE tblFriends.myID = '$myID') ORDER BY tblPosts.date DESC;

This doesn’t through an error but it also doesn’t work. I think I need a join statement maybe? There are several fields in tblPost. ID, Comment, Date, userID, etc… Using my $myID variable I want to output <<<while($row = $result->fetch_assoc())>>> all the matching rows from tblPosts WHERE tblPosts.usersID equals every friend in my tblFriends.friendsID column when tblFriends.myID = ‘$myID’ and then ORDER BY tblPosts.date DESC? Any help would be great! Thank you.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Just join your tables:

select p.*
from tblFriends f
join tblPosts p on p.userID = f.friendsID
where f.myID = '$myID'
order by p.date desc;

Also note the use of short table aliases makes for a more compact and easier to read query.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading