2012-04-11 43 views
0

我有一個顯示RSS提要的代碼,但它不會顯示主要內容。如何在RSS feed中將兩行數據放在一起MySQL

<?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顯示?一種方法是使用XSLT

在您的RSS生成腳本中,您沒有爲每個供稿項目定義的$row變量。你只是需要把周圍的RSS項目輸出的while($row = mysql_fetch_array($result)) - 是這樣的:

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>'; 
} 

編輯:在重新審視你的代碼:你還需要向上突破的領域在你description標籤。您不應該在其中放置td標籤 - RSS元素通常不包含HTML標記的數據。

像這樣的東西(如果這個意義上是有道理的):

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