multidim help for a newbie

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi :)

I am creating an XML file out of a mysql query with nested arrays.
Currently I can get 1 element and 1 child with a properly formatted XML file with the below script .


My question: is, How do I add 3 to 4 more child elements to the below 'playlist' array ?
Currently ,I have one parent 'Artist' and one child 'english' ...
I need to add more child elements like urlPath, spanish, biography, etc


Do I have to add another dimension to the 'playlist' array?

I am a bit new to this so any help would be greatly appretiated ....

<?php
@ $db = mysql_connect('127.0.0.1','name','pass');
	
	if (!$db)
	{
	echo 'Error:Could Not Connect';
	exit;
	}
	
	mysql_select_db('univision');


$sql = 'SELECT artist.artist_name, media.english, media.path '; $sql .= 'FROM media, artist '; $sql .= 'WHERE artist.artist_id = media.artist_id LIMIT 0, 30 ';

$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$playlist[$row['artist_name']] [] = $row['english'];
//would like to add more children here...
}

$xml = "<sirenreels>\n";

foreach ($playlist as $artist => $media)
{
$num_media = count($media);
   	$xml .= "<artist>\n";		
   	
   	$xml .= "\t<meta>\n";		
   	$xml .= 	"\t\t<title>".$artist."</title>\n";
	$xml .= "\t</meta>\n";	
	
	$xml .= "\t<content>\n";	

foreach ($media as $mediaVal)
{
			$xml .= "\t\t<media>\n";		
			$xml .= "\t\t\t<english_name>".$mediaVal."</english_name>\n";
			$xml .= "\t\t\t<path>".$mediaVal."</path>\n";	
			///add more children here
			$xml .= "\t\t</media>\n";	
			
}
		 	
	$xml .= "\t</content>\n";	
	$xml .= "</artist>\n";	
}
$xml .= "</sirenreels>\n";
print $xml

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux