0

データベースからデータを取って出演タイムテーブルを作ります。しかし、私の場合、データをファイル data *.xml に直接取ります

つまり、定期的なデータ収集のスケジューリングを行います。しかし、これにより、私が示すデータは動的ではありません。ファイル*を読み取ることしかできないためです。xml にします。私はphpで関数を作成し、xmlデータを次のように出力したい:

<?php
header("Content-type: text/xml");
$dbhost = "localhost";
$dbuser = "user";
$dbpass = "pass";
$dbname = "my_epg";
mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);

include "Encoding.php";

date_default_timezone_set("Asia/Jakarta");
$DataTanggal = strip_tags(date("l, jS, F Y"));

sql = "select distinct(channel_name) FROM epg";
$q   = mysql_query($sql) or die(mysql_error());
$xml = "<timetable start='00:00' end='24:00' title='".$DataTanggal."'>";

while($r = mysql_fetch_array($q)){
       $CN = htmlspecialchars(strip_tags($r['channel_name']));
           $xml .= "<location name='".$CN."'>"; 


        $sql2 = "select * FROM epg where channel_name='".$CN."'";
        $q2  = mysql_query($sql2) or die(mysql_error());

while($r2 = mysql_fetch_array($q2)){
    $Mulai      = htmlspecialchars(strip_tags(date('H:i', strtotime($r2['waktu_mulai']))));
    $Selesai    = htmlspecialchars(strip_tags(date('H:i', strtotime($r2['waktu_akhir']))));
    $Title      = htmlspecialchars(strip_tags($r2['judul']));
    $Desk       = htmlspecialchars(strip_tags($r2['sinopsis']));

      $Encoding1 = Encoding::fixUTF8($TitleValid);
      $Encoding2 = Encoding::fixUTF8($DeskValid);

    $xml .= "<event start='".$MulaiValid."' end='".$SelesaiValid."'>";
    $xml .= "<title>".$Encoding1."</title>";
    $xml .= "<description>".$Encoding2."</description>";
    $xml .= "</event>"; 
}

$xml .= "</location>";
}



$xml .= "</timetable>";
echo $xml;
?>

この成功した処理の結果は、アクセスした *.xml ファイルと同じように php ファイルと出力されます。今、timetable.class.php を使用してこのデータを処理する問題です。

public function createTimetable($url) {

    //Load xml file
    $xml = @simplexml_load_file($url, NULL, LIBXML_NOCDATA);

    if(!$xml) {
        echo 'Error: there is an error in your XML file: <a href="'.$url.'">'.$url.'</a>';
        return;
    }

    if (strpos($url, 'http://') === 0 || strpos($url, 'https://') === 0 || strpos($url, 'ftp://') === 0) {
        echo 'Error: the path to your xml file may not start with "http://"';
        return;
    }

    //Set the settings
    $this->setSettings($xml, $url);

    $this->writeHTML($xml);

    echo $this->mbencoding($this->output);
    return;

}

ただし、この関数は、既存のファイル (*.xml) からデータを読み取るためにのみ使用できます。動的phpプロセスではありません。

私の質問: この class.php でデータを取得または投稿してプロセスを作成し、データを動的にして、タイプ xml のプロセスを作成したリンクアドレスにアクセスできるようにするにはどうすればよいですか?

4

1 に答える 1