# PHP MYSQL DATA to XML FILE

**URL:** <https://forum.kirupa.com/t/php-mysql-data-to-xml-file/279970>\
**Category:** programming\
**Created:** [January 21, 2009, 5:37am UTC](https://forum.kirupa.com/t/php-mysql-data-to-xml-file/279970 "2009-01-21T05:37:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anthonynaly](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@anthonynaly](https://forum.kirupa.com/u/anthonynaly)\
**Post date:** [January 21, 2009, 5:37am UTC](https://forum.kirupa.com/t/php-mysql-data-to-xml-file/279970/1 "2009-01-21T05:37:50Z")

</div>

Good Day,

This is going to be my first post in this forums. Im having a problem with taking the data from my mysql database and output the data in an xml file. The script is working but the output xml misses 1 row in my mysql data.

Here is my php script…Thanks

\<?php

$fp = fopen("/xampp/htdocs/Playlist/$ipaddress.xml",‘w’);

$query = mysql\_query("Select \* FROM id\_playlist WHERE id\_playlist = ‘$ip\_ID’ ",$db);  
$row = mysql\_fetch\_array($query);

$xml\_output .= "\<?xml version=‘1.0’ encoding=‘UTF-8’?\>  
";  
$xml\_output .= "\<playlist version=‘1’ xmlns=‘[http://xspf.org/ns/0/](http://xspf.org/ns/0/)’\>  
";  
$xml\_output .= “\<trackList\>”;

for($x = 0 ; $x \< mysql\_num\_rows($query) ; $x++){  
$row = mysql\_fetch\_assoc($query);  
$xml\_output .= " \<track\>  
“;  
$xml\_output .= " \<title\>” . $row[‘title’] . "\</title\>  
“;  
$xml\_output .= " \<location\>” . $row[‘path’] . "\</location\>  
“;  
$xml\_output .= " \<identifier\>” . $row[‘id\_playlist’] . "\</identifier\>  
";  
$xml\_output .= " \</track\>  
";  
}

$xml\_output .= “\</trackList\>”;  
$xml\_output .= “\</playlist\>”;

$write = fwrite($fp,$xml\_output);

fclose($fp);

?\>
