mySQL php query - news/ friends feed

Posted by rpsep2 on Stack Overflow See other posts from Stack Overflow or by rpsep2
Published on 2013-10-19T15:49:40Z Indexed on 2013/10/19 15:53 UTC
Read the original article Hit count: 213

Filed under:
|

I want to show a user the recent uploads from their friends.

I have the users friends id's in an array:

$friends

A user could have, potentially, thousands of friends.

I can select the uploads from 1 of a users friends with:

$row = $mysqli->query("SELECT * FROM photos WHERE uploader_id =  ".$friend." ORDER BY date_uploaded DESC LIMIT ".$page.", 25");

But I need to find all of a users friends uploads. I thought about doing this in a loop iterating over the $friends array, but then I'd be potentially running thousands of mysql queries.

How can I do this most efficiently?

so to clarify:

search a 'photos' table for photos which are uploaded by specific users(friends), held in $friends variable, sort by date_uploaded and limit to x results so I can have pages 1, 2, 3 etc.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql