// Выбор id залогиненного пользователя (по id буду сортироваться сообщения в ленты новостей от пользоватей на которых он подписан ) $sqlForSubscriberByLogged = "SELECT id_request_reciver FROM subscribers WHERE id_request_sender='$loggedUser->id' "; $queryForSubscriberByLogged = $database->query($sqlForSubscriberByLogged); $fetch_arrayForSubscriberByLogged = $database->fetch_array($queryForSubscriberByLogged); // Здесь сортировка для ленты новостей от нужных пользователей на которых подписан залогившейся юзер. // Фильтрация данных будет идти от id_request_reciver $sqlForWallMessagesBySubscribers = "SELECT id_mes,id,text,sender,minute,hour,day,month,year FROM wall_messages WHERE id='$fetch_arrayForSubscriberByLogged[id_request_reciver]' ORDER BY id_mes DESC LIMIT 15"; $queryForWallMessagesBySubscribers = $database->query($sqlForWallMessagesBySubscribers); 

Need help properly "filter" the output of data for the news feed. That is, I select from the database those fields where my id is subscribed to other users with their id. The problem is that I only get the id of the LAST YEAR for which I have subscribed, but does not give out all (that is, not all the fields, but only one), in the cycle below just goes filtering by messages. enter image description here

Here's how it turns out. And I need something like this ... enter image description here

Thank you in advance for your help...

  • Do not pay attention to the inscriptions like "imvvairmoflo", this is for testing =) - Sergey Maley
  • one
    For fish, the text " Lorem ipsum ... " is generally accepted. Before the opening of this placeholder, I, too, let the cat walk through the clave - the best random text in the world, since no one will ever say what the cat will do in the next moment :) - user31688
  • @TheDoctor ahah) I will remember) - Sergey Maley
  • Here they use @ for addressing: @TheDoctor - user31688
  • Well, the problem is what you don’t know how to write the request correctly or what? - u_mulder

1 answer 1

Good day. First, as a wish I would like to say, shorten these long variable names. This is to nothing, yet you can write in application programming, where you add something to the standard component header, but here you just have php, so change it).

The second. Looking at your code:

 $sqlForSubscriberByLogged = "SELECT id_request_reciver FROM subscribers WHERE id_request_sender='$loggedUser->id' "; $queryForSubscriberByLogged = $database->query($sqlForSubscriberByLogged); $fetch_arrayForSubscriberByLogged = $database->fetch_array($queryForSubscriberByLogged); // Здесь сортировка для ленты новостей от нужных пользователей на которых подписан залогившейся юзер. // Фильтрация данных будет идти от id_request_reciver $sqlForWallMessagesBySubscribers = "SELECT id_mes,id,text,sender,minute,hour,day,month,year FROM wall_messages WHERE id='$fetch_arrayForSubscriberByLogged[id_request_reciver]' ORDER BY id_mes DESC LIMIT 15"; $queryForWallMessagesBySubscribers = $database->query($sqlForWallMessagesBySubscribers); 

You wonder why you have only one user comments listed? In the first request, you have to select records if they satisfy the condition for such id_request_sender = '$ loggedUser-> id, that is, the user specified, that one and then fetch is sent to the second request. It would be possible to combine this into one request simply, a little more complicated, but convenient and understandable. If you have difficulties with this, then read about how to combine data from several tables, in particular the WHERE, JOIN (LEFT, RIGHT, INNER) constructs, then everything will become clear). Good luck with your work!

  • Yes) At first . I just program in Objective-C, and I study php for myself, but I need to solve this problem, since I cannot launch the site =) For the second . Thank you, I will see how to combine in one request. But I was interested in another way with IN ( ) , as suggested above. - Sergey Maley