PHP & MySQL Dynamic RSS Code (Help)

I created a dynamic rss code using php and mysql. I created the code and everything looks in order. However, I am not getting any results in the rss page except the header.

Please find the code below

<?php
$host = "localhost"; // host name
$user = "";
$pass = "";

$database = "";

// connecting to database

$connect = @mysql_connect($host,$user,$pass)or die (@mysql_error());

// selecting database

@mysql_select_db($database,$connect) or die (@mysql_error());

// default header

header("Content-Type: text/xml;charset=utf-8");


    echo '<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title></title>
<description></description>
<link></link>';



// mytable = my content table name

$query = @mysql_query('
SELECT * FROM mt_news LIMIT 0,15 ORDER BY addeddate DESC');

while($row = @mysql_fetch_array($query)){

  $id=$row['news_id'];
  $title=strip_tags($row['news_title']);
  $body=strip_tags($row['news_description']);
  $body=substr($row['news_description'],0,150);

  // output to client


?>
     <item>
  <title><?print htmlentities($title,’ENT_QUOTES’);?></title>
  <description><?print htmlentities($body,’ENT_QUOTES’);?></description>
        <link>"http://".$_SERVER['HTTP_HOST']."/newsd-".$row['sef_link'];</link>
        <pubDate> <?=strftime( "%a, %d %b %Y %T %Z" , $row['addeddate']); ?></pubDate>
     </item>
<? } ?>

</channel>

</rss>

Appreciate your assistance

let us see var_dump($row); for the first iteration of fetch array please.

For the second time today on the forum, please move on from mysql_* extensions to PDO or mysqli.

I am sorry I didn’t get you. Can you show me what changes to make please…


<?php
$host = "localhost"; // host name
$user = ""; 
$pass = "";

$database = ""; 

// connecting to database

$connect = @mysql_connect($host,$user,$pass)or die (@mysql_error());

// selecting database

@mysql_select_db($database,$connect) or die (@mysql_error());

// default header

header("Content-Type: text/xml;charset=utf-8");


    echo '<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title></title>
<description></description>
<link></link>';

 

// mytable = my content table name

$query = @mysql_query('
SELECT * FROM mt_news LIMIT 0,15 ORDER BY addeddate DESC');

while($row = @mysql_fetch_array($query)){ 
var_dump($row); exit;

Thanks for your reply. I added the line and still getting no results

You weren’t supposed to get any results, you were supposed to get a var_dump result and post it back to us :slight_smile:

where can I get the results from?