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