0

I am generating an php array and then converting it to a xml playlist. converting array to xml is no problem, but i am having problem generating the array. I am getting data from DB and want to use it. My code is like bellow-

$songs2008 = get_data("musics", "where year='2008'");
$mysongs = array();
foreach($songs2008 as $k1=>$v1){
    $entry = array(
        "url"=>"songs/main_songs/".$v1[file_name],
        "songname"=>$v1[song_title],
        "artist"=>$v1[artist]
    );
    array_push($mysongs, $entry);
}

and the array is -

$array = array(
    "settings"=>array(
    "width"=>"316",
        "songs"=>array(
        "albumArt"=>array(
        "url"=>"songs/2008.jpg",
        "entries"=>array(
            "entry"=>$mysongs['0'],
                        "entry"=>$mysongs['1'],
                        "entry"=>$mysongs['2'],
                        ----------------------
                        ----------------------
            )
        )
    )

);

Its not working at the entries. the array key is same(entry); so only one showing. is there any solution? any other way to do it? please help.

2 Answers 2

1

It's because you can't use 'entry' as an index more than once. Try:

"entries" => $mysongs

@see: http://php.net/manual/de/language.types.array.php for further reading an php arrays

But be carefull, you'll propably be running into some problems creating your xml code when using this. For I would bet that you are using the array keys as tag names!

Sign up to request clarification or add additional context in comments.

Comments

0

Don't name your array key for "entry"

$array = array(
    "settings"=>array(
    "width"=>"316",
        "songs"=>array(
        "albumArt"=>array(
        "url"=>"songs/2008.jpg",
        "entries"=>array(
            $mysongs['0'],
            $mysongs['1'],
            $mysongs['2'],
                        ----------------------
                        ----------------------
            )
        )
    )

);

1 Comment

I am using array keys as xml tag name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.