Answer the question
In order to leave comments, you need to log in
Append data to mysql in a loop?
Hello. I'm trying to add data to the database. Here is the code
require_once 'connection.php';
$link = mysqli_connect($host, $user, $password, $database) or die('Не смог подключиться к БД' . mysqli_error($link));
for ($i = 0; $i < count($yagoo_res); $i++) {
$arr = [];
array_push($arr, $yagoo_res[$i]);
for ($k = 0; $k < 10; $k++) {
array_push($arr, $result["results"][$k]['url']); //добавляем результирующий массив УРЛов в сборный массив результатов запросов
}
$query = "INSERT INTO array VALUES(NULL, '$arr[0]','$arr[1]','$arr[2]','$arr[3]','$arr[4]','$arr[5]','$arr[6]','$arr[7]','$arr[8]','$arr[9]','$arr[10]')";
print_r($arr);
array_push($arr2, $arr);
}
$result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
mysqli_close($link);
Array ( [0] => 12512655 [1] => https://www.makfsa.ru/ [2] => https://ru.wikipsedia.org/wiki/%D0%9C%D0%B0%D0%BA%D1%84%D0%B0 [3] => http://makfa.nichosst.ru/ [4] => http://ru.makfapasta.com/production/product/pasta/ [5] => http://ru.makfapasta.com/ [6] => https://www.utkaonos.ru/item/42/1096519 [7] => https://www.utkonos.ru/item/42/1096522 [8] => https://www.utkonos.ru/item/1381/3223485 [9] => https://www.uatkonos.ru/item/42/1096527 [10] => https://proactions.ru/actions/food/makfa/ )
Answer the question
In order to leave comments, you need to log in
your_uncle looks like you haven't tried reading your own code.
at what here texts of requests?
mysqli_query($link, $query) sends $query to be executed.
Everything that was written-overwritten in $query before is absolutely not important.
It is only important that it was stored there specifically at the time of the mysqli_query call.
you need instead of the line print_r($arr); put mysqli_query and everything will work (of course, if you have the correct table structure, etc.)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question