How to provide RSS feed from our website

Discussion in 'XML & RSS' started by johneva, Jan 5, 2011.

  1. #1
    Hi all

    Website in question - http://www.lease-hire.co.uk

    We currently have a news section on our website thats done with PHP where we add the news through a control panel and then the data is stored in the database just the same as a blog like wordpress really I suppose.

    My question is how do I go about making an RSS feed with this news on the website?

    I know the idea is you need to make an xml file with the tags: title, description and link. But if its an XML file then how do I connect to our database to provide the last 10 news articles and tag them as needed, as the PHP to request the data from the database wont be parsed will it?

    Cheers
    John Eva
     
    johneva, Jan 5, 2011 IP
  2. Reveille

    Reveille Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Not sure if PHP would be my language of choice for connecting to a DB but I did a quick google search and came up with the following code:
    <?php
    $username = "your_name";
    $password = "your_password";
    $hostname = "localhost"; 
    
    //connection to the database
    $dbhandle = mysql_connect($hostname, $username, $password) 
     or die("Unable to connect to MySQL");
    echo "Connected to MySQL<br>";
    
    //select a database to work with
    $selected = mysql_select_db("examples",$dbhandle) 
      or die("Could not select examples");
    
    //execute the SQL query and return records
    $result = mysql_query("SELECT id, model,year FROM cars");
    
    //in here youll have to filter out your results to just the newest 10 entries
    $result = $result.(sort by desending date)//how you actully accomplish this depends on what DB you are connecting to and which language your using
    
    //fetch tha data from the database 
    while ($row = mysql_fetch_array($result)) {
       echo "ID:".$row{'id'}." Name:".$row{'model'}."Year: ". //display the results
       $row{'year'}."<br>";
    }
    //close the connection
    mysql_close($dbhandle);
    ?> 
    
    
    Code (markup):
     
    Reveille, Jan 15, 2011 IP
  3. johneva

    johneva Well-Known Member

    Messages:
    1,480
    Likes Received:
    46
    Best Answers:
    1
    Trophy Points:
    170
    #3
    Thats not really what I was asking for though is it?

    That simpley does what my news page already does, I need to make an XML file for an RSS feed.
     
    johneva, Jan 17, 2011 IP
  4. buddyborg

    buddyborg Guest

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    buddyborg, Jan 19, 2011 IP