SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Aug 2013
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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 Code:
    <?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

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,180
    Mentioned
    65 Post(s)
    Tagged
    2 Thread(s)
    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.

  3. #3
    SitePoint Member
    Join Date
    Aug 2013
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am sorry I didn't get you. Can you show me what changes to make please..

  4. #4
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,180
    Mentioned
    65 Post(s)
    Tagged
    2 Thread(s)
    Code PHP:
    <?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;

  5. #5
    SitePoint Member
    Join Date
    Aug 2013
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your reply. I added the line and still getting no results

  6. #6
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,180
    Mentioned
    65 Post(s)
    Tagged
    2 Thread(s)
    You weren't supposed to get any results, you were supposed to get a var_dump result and post it back to us

  7. #7
    SitePoint Member
    Join Date
    Aug 2013
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where can I get the results from?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •