2012-04-11 140 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>";