2012-04-11 4 views
0

RSSフィードを表示するコードがありますが、メインのコンテンツは表示されません。RSSフィードでMySQLから2行のデータをまとめて入力する方法

<?PHP 
include("../config.php"); 
#// Timetable Clearup Variabls 
$yesterday = strtotime('yesterday'); 
$yesterdow = date('l',$yesterday); 
$order = "SELECT * FROM timetable WHERE day = '$yesterdow' ORDER BY time"; 
$result = mysql_query($order); 
$yesterdayd = date('F jS, Y', time()-86400); 

    //SET XML HEADER 
    header('Content-type: text/xml'); 

    //CONSTRUCT RSS FEED HEADERS 
    $output = '<rss version="2.0">'; 
    $output .= '<channel>'; 
    $output .= "<title>Timetable - {$yesterdayd} </title>"; 
    $output .= '<description>Timetable.</description>'; 
    $output .= '<link>http://example.com/</link>'; 
### $output .= '<copyright>Your copyright details</copyright>'; 

    //BODY OF RSS FEED 
    $output .= '<item>'; 
     $output .= "<title>Timetable for $yesterdayd</title>"; 
     $output .= "<description><td>" . htmlspecialchars($row['username']) . "</td><td>" . htmlspecialchars($row['time']) . "</td></description>"; 
     $output .= '<link>Link to Item</link>'; 
     $output .= '<pubDate>Date Published</pubDate>'; 
    $output .= '</item> '; 

    //CLOSE RSS FEED 
    $output .= '</channel>'; 
    $output .= '</rss>'; 

    //SEND COMPLETE RSS FEED TO BROWSER 
    echo($output); 

?> 

私は問題を抱えているビットは、次のとおり

$output .= "<description><td>" . htmlspecialchars($row['username']) . "</td><td>" . htmlspecialchars($row['time']) . "</td></description>"; 

私は基本的にフィードに出力するように各行のデータを必要とします。ここで

は、私は(私が好きなフォーマットである、テーブルに)通常はそれを行うことができます方法は次のとおりです。

<?php 
include("../config.php"); 

#// Timetable Clearup Variabls 
$yesterday = strtotime('yesterday'); 
$yesterdow = date('l',$yesterday); 

echo "<table width=\"580px\" class=\"board\" border=\>"; 

$order = "SELECT * FROM timetable WHERE day = '$yesterdow' ORDER BY time"; 
$result = mysql_query($order); 

// Error checking 
if (!$result) { 
    // output error, take other action 
} 
else { 
    while ($row=mysql_fetch_array($result)){ 
    // Append all results onto an array 
    $rowset[] = $row; 
     echo "<tr><td>" . htmlspecialchars($row['username']) . "</td><td>" . htmlspecialchars($row['time']) . "</td></tr>"; 
    } 
} 





?> 

答えて

0

あなたがテーブルにRSSを表示する意味はどうすればよいですか? HTMLやRSS(XML)を作成しますか?あるいは、RSSをHTMLディスプレイに変換することについて話しているのでしょうか? 1つの方法は、そのためにXSLTを使用することです。

RSS生成スクリプトでは、フィード項目ごとに$row変数が定義されていません。

while ($row = mysql_fetch_array($result)) { 
    $output .= '<item>'; 
    $output .= "<title>Timetable for $yesterdayd</title>"; 
    $output .= "<description><td>" . htmlspecialchars($row['username']) . "</td><td>" . htmlspecialchars($row['time']) . "</td></description>"; 
    $output .= '<link>Link to Item</link>'; 
    $output .= '<pubDate>Date Published</pubDate>'; 
    $output .= '</item>'; 
} 

EDIT:あなたのコードを再検討する上:あなたもあなたのdescriptionタグ内のフィールドを分割する必要があり、このような何かを - あなたはRSSアイテムの出力の周りwhile($row = mysql_fetch_array($result))を配置する必要があります。 tdタグをそこに入れてはいけません。RSS要素は(通常は)HTMLマークアップされたデータを含むものではありません。

(この意味は理にかなっている場合)、このような何か:

$output = "<description> 
    <username>" . htmlspecialchars($row['username']) . "</username> 
    <time>" .  htmlspecialchars($row['time']) . "</time> 
</description>"; 
関連する問題