I need to do N queries according to a value received from another query.
$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 the case, I stored the results in a vector, but I do not know if this is 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 is there another way to get and organize the data?
And if in case it is vector, any suggestions on how to organize by date?
Thank you.