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
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):
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.