www.webdeveloper.com
Results 1 to 4 of 4

Thread: generating a RSS feed from php (code problem)

  1. #1
    Join Date
    Dec 2005
    Posts
    123

    generating a RSS feed from php (code problem)

    Hi guys, i found a script on the net which creates a xml file from a mysql driven php file. I wish to modify this script so that it creates a valid RSS feed. I'm having a bit of difficulty. This is my code:
    PHP Code:
    <?php

    $db_name 
    "*********";
    $link mysql_connect("*********""*********""*********") or die("Could not connect to server!");

    $table_name 'mynews';

    $select_db mysql_select_db($db_name$link);
    $query "SELECT * FROM mynews " $table_name;
    $result mysql_query($query$link) or die("Could not complete database query");Send a MySQL query
    $num 
    mysql_num_rows($result); 

    if (
    $num != 2) {

      
    $filefopen("rss.xml" "w"); 
      
    $_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
      
    $_xml ="<rss version='2.0'>\r\n";
      
    $_xml .="<channel>\r\n";

      while (
    $row mysql_fetch_array($result)) {
        
    $_xml .=" <item>\r\n";

        
    $_xml .="   <title>" $rowtitle] . "</title>\r\n";
        
    $_xml .="   <content>" $rowcontent] . "</content>\r\n";
        
    $_xml .="   <message>" $rowmessage] . "</message>\r\n";



        if (
    $row[website]) {
          
    $_xml .="   <user>" $rowuser] . "</user>\r\n";
        } else {

        }


        
    $_xml .=" </item>\r\n";
      }

      
    $_xml .="</channel>";


      
    fwrite($file$_xml);
      
    fclose($file); 


      
      echo 
    "<a href=rss.xml>RSS FEED</a>";

    } else {
      echo 
    "No Records found";
    }

    ?>
    With the above code i get an error in my XML page which reads
    XML Parsing Error: no element found
    Location: http://pixelscience.it/rss.xml
    Line Number 33, Column 9:</channel>
    --------^
    I'm pretty sure i have a problem with this line too:
    $_xml ="<rss version='2.0'>\r\n";

    Doubt that is valid tbh.

  2. #2
    Join Date
    Jun 2004
    Location
    4846′36″ N 910′48″ E
    Posts
    3,747
    You are missing a concatenation operator before the equal sign:
    PHP Code:
    $_xml ="<rss version='2.0'>\r\n"
    PHP Code:
    $_xml .="<rss version='2.0'>\r\n"

  3. #3
    Join Date
    Dec 2005
    Posts
    123
    added the operator but i'm afraid it didn't reslove the error

  4. #4
    Join Date
    Jun 2004
    Location
    4846′36″ N 910′48″ E
    Posts
    3,747
    PHP Code:
    $result mysql_query($query$link) or die("Could not complete database query");Send a MySQL query 
    Are you having this line with the text at the end in your code?!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles