hi i want to store the url in the list loop that comes from db using primary key and foreign key but I don't know how to store the url in each list and have the same id in the first table and the second table what i want to do is something like this
Array
(
name : 'test',
detail : 'detail',
[url] => Array
(
[episode1] => Array
(
[link] => https://
)
[episode2] => Array
(
[link] => https://azeaze32a
)
)
)
i did all loops 'for,while,'foreach' and sat for a whole day but i fail every time this is my code:
<?php
$select_list_movies = select("SELECT * from list_movies");
$arr =[];
$i =0;
while($rows = mysqli_fetch_assoc($select_list_movies)) {
$id = $rows['id'];
//print_r($rows);
$select_list_link = select("SELECT links.link FROM `list_movies`inner join links on list_movies.id = links.movie_id where list_movies.id = '$id'");
foreach ($select_list_link as $key1) {
$i ;
$arr = [
'url' => ['episode'.$i => $key1]
];
print_r($arr); // here print all url i want to put every links of every movie if there are links
}
}
?>
If anything is not clear write your answer i'll reply to u if i can
CodePudding user response:
You're replacing $arr
each time through the loop, you need to add to the url
element.
<?php
$select_list_movies = select("SELECT * from list_movies");
$arr =['name' => 'test', 'detail' => 'detail', 'url' => []];
$i =0;
while($rows = mysqli_fetch_assoc($select_list_movies)) {
$id = $rows['id'];
//print_r($rows);
$select_list_link = select("SELECT links.link FROM `list_movies`inner join links on list_movies.id = links.movie_id where list_movies.id = '$id'");
foreach ($select_list_link as $key1) {
$i ;
$arr['url']['episode'.$i] = $key1;
print_r($arr); // here print all url i want to put every links of every movie if there are links
}
}
?>