我有一个显示RSS提要的代码,但它不会显示主要内容。
<?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>";
}
}
?>
你想在
表格中显示 rss 是什么意思?你想创建HTML还是RSS(XML)? 或者,也许您正在谈论将RSS转换为HTML显示? 一种方法是使用 XSLT
。在生成 RSS 的脚本中,您没有为每个源项定义$row
变量。您只需将while($row = mysql_fetch_array($result))
放在rss项目输出周围 - 如下所示:
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>";