Help me to create an XML format like this :
http://telkomvision.com/soap/timetable/monday.xml
The code that I have made like this :
<?php
date_default_timezone_set("Asia/Jakarta");
$NowDate = date("Y-m-d G:i:s");
$FormatWM = date('Y-m-d',strtotime($NowDate));
$FormatLagi = date('Y-m-d',strtotime($NowDate));
mysql_connect("localhost", "root", "");
mysql_select_db("telkncom_epg");
$namaTabel = "epg";
header('Content-Type: text/xml');
$query = "SELECT * FROM $namaTabel where tgl_mulai='26-SEP-12' limit 0,30";
$hasil = mysql_query($query);
$jumField = mysql_num_fields($hasil);
echo "<?xml version='1.0' ?>";
echo "<data>";
while ($data = mysql_fetch_array($hasil))
{
echo "<".$namaTabel.">";
for ($i=0; $i<=$jumField-1; $i++)
{
$namaField = mysql_field_name($hasil, $i);
echo "<".$namaField.">".$data[$namaField]."</".$namaField.">";
}
echo "</".$namaTabel.">";
}
echo "</data>";
?>
And my code result is :
http://telkomvision.com/soap/timetable/CreateXML.php
My Database design :
| id | channel_code | channel_name | date | s_time | e_time | topic | sinps |
What should I change in my code to get the results that I want?
Bertho, you should look into XQuery as an option for restructuring XML documents. There are also several software vendors offering SQL applications, some free some paid, which have XML handlers. Unless you’re trying to avoid using a querying language, I think that you should use a querying language rather than PHP. I struggled to edit XML in PHP for a long time, and I’ve found that creating code that’s as well made as the query language code via PHP isn’t worth the effort. You’re going to be troubleshooting errors and adding routines to handle errors and exceptions and struggling to optimize for months if you use PHP, I think; on the other hand, you could use a query language for a day or two and be through with it. XQuery is very easy to learn, it’s web standards, and it supports XPath 2.0. You’ll definitely be happier with that than you are with XPath or SimpleXML. You also might consider XSLT. Some people prefer that because it requires less administration, but I like XQuery better for its simplicity.
If you’re willing to work with XQuery, I think I can post the code necessary.