0
I need to do N consultations according to a value received from another consultation.
$idList = array();
if (@$_GET["page"] == "profile"){
$idList[0] = $_GET['pid'];
$cont = 0;
}
else {
$idList[0] = $uid;
$cont = 1;
$query = mysqli_query($conn, "SELECT * FROM `friends_list` WHERE user_id = '$uid'");
while($friends = mysqli_fetch_array($query)){
$idList[$cont] = $friends['friend_id'];
$cont++;
}
$cont = count($idList);
$cont--;
}
$pos = 1;
while($cont>= 0){
$id = $idList[$cont];
$query2 = mysqli_query($conn,"SELECT * FROM `post` WHERE user_id = $id'");
while($posts = mysqli_fetch_assoc($query2)){
$pList[$pos] = $posts;
$pos++;
}
$cont--;
}
$cont = 1;
foreach($pList as $post){
$id = $post['user_id'];
$query3 = mysqli_query($conn,"SELECT * FROM `profile` WHERE id = '$id' LIMIT 1") or die(mysqli_error($conn));
$owner = mysqli_fetch_assoc($query3);
In this case, I’ve stored the results in a vector, but I’m not sure that’s the best way to do it. Detail, I have no idea how to organize the vector effectively because the amount of results can be very large.
What is the best way to do this search? Through vector or there is another way to get and organize the data?
And if it is vector, any suggestions of how to organize by date?
Thank you.
You want to organize the query by date, right? Why don’t you use the
order by <nome_da_coluna_que_armazena_a_data
?– Flávio Santos
Exactly, but they are several different users_ids with multiple possibilities for each one. Ie: user_id = 1, date 27/09/2018 user_id = 1, date 25/09/2018 user_id = 3, date 1/10/2018 user_id = 4, date 30/09/2018
– Marciohrm
So I have to interim these user_ids ordered by date.
– Marciohrm
You have to sort by date, but the
user_id
'Do you have to stick together? That?– Flávio Santos
No, the ids appear in the order of the date. Style social media posts to show the posts of friends and the user himself according to the date of publication.
– Marciohrm
do you want to load a 'Timeline'? , with posts sorted by date? But in this case, why do you need
user_id
s? I think I understand, but I would like you to give some more details– Flávio Santos
That’s right. I need user_id to control who’s friends with who, you know? He picks up posts from friends only.
– Marciohrm