I trying to order a query inside a foreach loop. After looking around reasoning why its not displaying the results correctly I've read that the foreach will only run once for every user its found so its basically just ordering that one users updates.
$AllFriend = explode(",", $UserInfo['friends']);
array_push($AllFriend, $Username);
foreach ($AllFriend as $FriendSel) {
$sql5 = "SELECT * FROM updates WHERE username = :username ORDER BY id DESC LIMIT 20";
$DoQuery = $pdo->prepare($sql5);
$DoQuery->bindValue(':username', $FriendSel);
$DoQuery->execute();
while ($Updates = $DoQuery->fetch(PDO::FETCH_ASSOC)){
I have the friends in the database like "friend1, friend2, friend3" etc so I'm using array_push to add the users username in to be able to see their own updates to as you wouldn't add yourself as a friend.
What would I need todo to be able to get the updates ordering by ID.
I'm not wanting someone to just show me what todo and thats it as I want to learn so pointing me in the right direction would be great!
Thank you!
source https://stackoverflow.com/questions/69003893/ordering-in-a-foreach-loop
Comments
Post a Comment