Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

store url in same list with id php sql

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
    }
}

?>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading