Jump to content

while loop not showing anything


nicky666

Recommended Posts

Hi i'm trying to create a rss page, the problem I have is that the data is not showing. If I check the page source the data is there but it's not showing up and I can't seem to figure out why or how to fix it.

<?php
ini_set('display_errors', 1);
header("Content-type: text/xml");
include("includes/database.php");
global $NEWS;
$str = '<?xml version="1.0" encoding="UTF-8"?>';
$str.= '<rss version="2.0">';
$str.='<channel>';
$sql = "SELECT * FROM news";

$result = mysql_query($sql) or die ($sql."".mysql_error());

while($row = mysql_fetch_object($result)){
    $str.= '<item>';
    $str.= '<title>'.$row->title.'</title>';
    $str.= '<description>'.$row->content. '</description>';
    $str.= '</item>';
}

$str .='</channel>';
$str .='</rss>';
echo $str;
Link to comment
https://forums.phpfreaks.com/topic/285743-while-loop-not-showing-anything/
Share on other sites

I validated the feed and I got this

 

 

This feed does not validate.

  • line 1, column 113: Undefined description element: p [help]

    ... title>xzfbcbcxv 123</title><description><p>Mr. Kim Keats-Martínez, Execu ...                                             ^

  • line 1, column 116: XML parsing error: <unknown>:1:402: not well-formed (invalid token) [help]

    ... le>xzfbcbcxv 123</title><description><p>Mr. Kim Keats-Martínez, Executiv ...

I'm not sure how I'm going to fix this as the cms I'm using puts the <p> tag automatically

You need to contain your HTML within CDATA. Otherwise the XML parser thinks it is part of your XML structure and so you'll get validation errors.

$str.= '<description><![CDATA['.$row->content. ']]></description>';

Alternatively convert the html to htmlentities

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.