Advertisement
joris

XML

Sep 27th, 2012
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. <?php
  2. $dbhost = "localhost";
  3. $dbuser = "berthowe_ulatih";
  4. $dbpass = "hcw!D3w3M7Lt";
  5. $dbname = "berthowe_latihan";
  6. mysql_connect($dbhost,$dbuser,$dbpass);
  7. mysql_select_db($dbname);
  8.  
  9.  
  10. $sql = "select distinct(channel_name) FROM epg";
  11. $q   = mysql_query($sql) or die(mysql_error());
  12. $xml = "<timetable start='00:00' end='24:00' title='Friday, September 28th, 2011'>";
  13.  
  14. while($r = mysql_fetch_array($q)){
  15.        $CN = htmlspecialchars($r['channel_name']);
  16.        $xml .= "<channel name='".$CN."'>";
  17.    
  18.     $sql2 = "select * FROM epg where channel_name='".$CN."'";
  19.     $q2  = mysql_query($sql2) or die(mysql_error());
  20.    
  21.     while($r2 = mysql_fetch_array($q2)){
  22.         $Mulai      = htmlspecialchars(date('H:i', strtotime($r2['waktu_mulai'])));
  23.         $Selesai    = htmlspecialchars(date('H:i', strtotime($r2['waktu_akhir'])));
  24.         $Title      = htmlspecialchars($r2['judul']);
  25.         $Desk       = htmlspecialchars($r2['sinopsis']);
  26.        
  27.         if($Mulai==""){
  28.             $MulaiValid = "Kosong";
  29.         }else{
  30.             $MulaiValid = $Mulai;
  31.         }
  32.        
  33.         if($Selesai==""){
  34.             $SelesaiValid = "Kosong";
  35.         }else{
  36.             $SelesaiValid = $Selesai;
  37.         }
  38.        
  39.         if($Title==""){
  40.             $TitleValid = "Kosong";
  41.         }else{
  42.             $TitleValid = $Title;
  43.         }
  44.        
  45.         if($Desk==""){
  46.             $DeskValid = "Kosong";
  47.         }else{
  48.             $DeskValid = $Desk;
  49.         }
  50.        
  51.           $xml .= "<event start='".$MulaiValid."' end='".$SelesaiValid."'>";
  52.           $xml .= "<title>".$TitleValid."</title>";
  53.           $xml .= "<description>".$DeskValid."</description>";
  54.           $xml .= "</event>";  
  55.     }
  56.    
  57.     $xml .= "</channel>";
  58. }
  59.  
  60.    
  61.  
  62. $xml .= "</timetable>";
  63. //print $xml;
  64. $sxe = new SimpleXMLElement($xml);
  65. $sxe->asXML("epg.xml");
  66.  
  67. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement