Answer the question
In order to leave comments, you need to log in
How to get data from database into array?
I retrieved the data from the database in the order I needed:
$friends = 'SELECT friend FROM `friends` WHERE id="'.$id.'" and value=1';
$listfriends = mysqli_query($connection, $friends) or die("Ошибка");
while($returnlist = mysqli_fetch_row($listfriends)) {
print $returnlist[0]; // Выводит 1, 2, 3 (только слитно)
}
echo $returnlist[0]; // Чтобы вывел не 1, 2, 3, а 1.
echo $returnlist[1]; // Чтобы вывел 2.
echo $returnlist[2]; // Чтобы вывел 3.
Answer the question
In order to leave comments, you need to log in
$data = [];
while($returnlist = mysqli_fetch_row($listfriends)) {
$data[] = $returnlist[0];
}
echo $data[0];
echo $data[1];
...
In short, you can do this:
$SQL = 'SELECT friend FROM `friends` WHERE id="'.$id.'" and value=1';
$requestResult = mysqli_query($connection, $SQL) or die("Ошибка");
$arFriends = [];
while($resultRow = mysqli_fetch_row($requestResult)) {
$arFriends[] = $resultRow[0];
}
echo $arFriends[0]; //Должно вывести 1
echo $arFriends[1]; //Должно вывести 2
// и.т.д
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question