Answer the question
In order to leave comments, you need to log in
How to correctly select data from an array using the SELECT method?
The code with which I select the user's friends
$listfriends = 'SELECT friendid FROM `friends` WHERE userid="'.$id.'" and relation=1';
$listfriendssql = mysqli_query($connection, $listfriends) or die("Ошибка");
$data = [];
while($returnlist = mysqli_fetch_row($listfriendssql)) {
$data[] = $returnlist[0];
echo $data[1]; // выведется id юзера
$datasql = "SELECT name FROM `users` WHERE id=$data[0]"; // Из этого массива выводится имя, которое равно id из массива. То есть этот код нормально работает.
$querynameselect = mysqli_query($connection, $datasql) or die("Ошибка");
$data = mysqli_fetch_array($querynameselect);
echo $data[0];
$datasql = "SELECT name FROM `users` WHERE id=$data[1]";
Answer the question
In order to leave comments, you need to log in
It is necessary to call mysqli_fetch in a cycle, as is done in the first query.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question