S
S
Sergey Maley2015-04-15 20:12:56
PHP
Sergey Maley, 2015-04-15 20:12:56

News feed in php (problem with request), how to implement 2 requests into one?

Need help to correctly "filter" the data feed output. That is, I select from the database those fields where my id is subscribed to other users with their id. The problem is WHAT gives me only the id of the LAST USER to which I subscribed, and does not give out all (that is, not all fields, but only one), in the cycle below there is simply filtering by messages.

// Выбор id залогиненного пользователя (по id буду сортироваться сообщения в ленты новостей от пользоватей на которых он подписан )
$sqlForSubscriberByLogged	   = "SELECT id_request_reciver FROM subscribers WHERE id_request_sender IN('$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 IN($fetch_arrayForSubscriberByLogged[id_request_reciver]) ORDER BY id_mes DESC LIMIT 15"; //IN()
$queryForWallMessagesBySubscribers = $database->query($sqlForWallMessagesBySubscribers);

It should turn out like this
f31c4eac26c147c08558bc6cbbaf51cb.png
. And it displays the content of only one user to which I am subscribed, and I am subscribed to 2 users ...
60a6ffc4a7314b5497ea68a8968374cd.png
I asked this question here, Go
But I did not find a solution.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Sergey Maley, 2015-04-15
@spesher

Problem solved!
Thanks everyone for the tips and help.
Here's what I changed..
Result.
I also wanted to ask what to add in the request in order to see my entries in the feed?

F
FanatPHP, 2015-04-15
@FanatPHP

The very first thing to say is:
Don't give temporary variables super-informative names.
In the end it should be

$sql = "SELECT id_request_reciver FROM subscribers WHERE id_request_sender = ..."; 
$SubscriberByLogged = $database->query($sql)->fetch_array();

R
Reistlin, 2015-04-15
@iznaur

If I understand you correctly, read about combining queries , you need something like this:

$database->query("SELECT (поля которые вам нужны из этих таблиц в виде таблица.поле) FROM subscribers LEFT JOIN wall_messages ON subscribers.id_request_reciver=wall_messages.id WHERE subscribers.id_request_sender = $loggedUser->id")->fetch_array();

M
Mikhail Tikhonin, 2015-04-15
@phpclimber

Look with a wardump what you have in the $sqlForWallMessagesBySubscribers variable and you will surely find an error.

A
Andrey Mokhov, 2015-04-15
@mokhovcom

kick variables...
instead of $fetch_arrayForSubscriberByLogged[id_request_reciver] you need implode(',', $fetch_arrayForSubscriberByLogged)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question