douer9399 2012-04-11 20:03
浏览 20

如何在RSS feed中将MySQL的两行数据放在一起

I've got a code that displays an RSS feed but it won't display the main content.

 <?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);

?>

The bit I'm having issue with is:

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

I basically need to output the data from each row onto the feed.

Here's how I can do it normally (into a table, which is the format I'd like):

<?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>";
  }
}





?> 
  • 写回答

1条回答 默认 最新

  • douci4026 2012-04-11 20:19
    关注

    How do you mean you want to display the rss in a table? Do you want to create HTML or RSS (XML)? Or maybe you are talking about transforming the RSS into an HTML display? One way is to use XSLT for that.

    In your RSS-generating script, you don't have a $row variable defined for every feed item. You need to just place the while($row = mysql_fetch_array($result)) around the rss item output - something like this:

    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: on re-examining your code: you also need to break up the fields in your description tag. You should not put td tags in there - the RSS elements are not (normally) meant to contain HTML marked-up data.

    Something like this (if this meaning makes sense):

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

报告相同问题?

悬赏问题

  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000