PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I've adapted some code to create an RSS feed from my database. It seems to work fine except for the fact that it only returns 1 result when there are many in the database. I'm not very technical (marketing person!) but I'm just trying to build a proof of concept site. Any help would be appreciated. Thanks. Shaun.
I'm still struggling with this. The "For" statement works well except that it returns blank lines when my database contains less entries than 20. I'm just looking for a way to loop through and output results as long as the row contains values. Here is the code that I'm trying but as mentioned above it causes my browser to crash when I run it as it seems to enter into a never ending loop:
mysql_connect ("localhost", $username, $password) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db($database) or die(" Unable to select db: ".mysql_error());
$query = "SELECT t1.*, t2.*
FROM sgj_notices AS t1 INNER JOIN sgj_contentbuilder_records AS t2 ON (t1.storage_id=t2.reference_id AND t1.id=t2.record_id)";
$result = mysql_query($query) or die("Query failed") ;
echo
'<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
<channel>
<title>'.$rss_title.'</title>
<link>http://.'.$rss_site.'</link>
<description>'.$rss_description.'</description>
<language>en-en</language>
<image>
<url>'.$rss_logo.'</url>
<title>'.$rss_site.'</title>
<link>http://www.'.$rss_site.'</link>
</image>';
while($row = mysql_fetch_array($result)) {
$subject = mysql_result($result,$i,'t1.Notice_Title');
$description = mysql_result($result,$i,'t1.Notice_Text');
// Clean the description
$description = str_replace ("&","",htmlspecialchars(strip_tags($description)));
$link = mysql_result($result,$i,'t1.Notice_Link');
//to record when the feed was published
$pubdate = mysql_result($result,$i,'t2.publish_up');
//format the date
$format = 'D, d M Y H:i:s O';
$pubdate = date_format(date_create($pubdate), $format);
echo '
<item>
<title>'.$subject.'</title>
<link>'.$link.'</link>
<description>'.$description.'</description>
<pubDate>'.$pubdate.'</pubDate>
</item>
';
} //end of the while loop
mysql_close(); //close the DB
echo '
</channel>
</rss>
';
?>
Try Celauren's code. That's the right way to loop through resultset obtained from your query.
Your query seems to be correct, but if you are getting the same record multiple times, change query to add "distinct" and see if you are getting distinct records. If you get only 1 record, well then you have duplicate data in your table..