请帮助我在 php 中执行该过程,以便我获取从变量派生的数据。在这种情况下,我创建了一个用于创建 xml 文件的 php 文件。在这里,我得到了数据,即频道,我希望该频道中的每个父母都将输入数据。请看我的代码:
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "db_epg";
mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);
$sql = "select distinct(channel_name) FROM epg";
$q = mysql_query($sql) or die(mysql_error());
$xml = "<timetable start='00:00' end='24:00' title='Friday, September 28th, 2011'>";
while($r = mysql_fetch_array($q)){
$CN = $r['channel_name'];
$xml .= "<channel>".$CN."</channel>";
}
$xml .= "</timetable>";
$sxe = new SimpleXMLElement($xml);
$sxe->asXML("epg.xml");
?>
我的代码的结果是:http ://s9.postimage.org/rjsodf9mn/result.png
如果我想做一个循环,在每个数据通道上都会没有数据子,那我该怎么办呢?
我尝试在这个while部分进行另一个查询:
while($r = mysql_fetch_array($q)){
$CN = $r['channel_name'];
$xml .= "<channel>".$CN."</channel>";
$sql2 = "select * FROM epg where channel_name='".$CN."'";
$q2 = mysql_query($sql2) or die(mysql_error());
while($r2 = mysql_fetch_array($q2)){
$Mulai = date('H:i', strtotime($r2['waktu_mulai']));
$Selesai = date('H:i', strtotime($r2['waktu_akhir']));
$Title = $r2['judul'];
$Desk = $r2['sinopsis'];
$xml .= "<event start='".$Mulai."' end='".$Selesai."'>";
$xml .= "<title>".$Title."</title>";
$xml .= "<description>".$Desk."</description>";
$xml .= "</event>";
}
}
但我失败了。有人能帮我吗??