Revisited: Creating an XML Content Feed With PHP - Creating a sample content feed (contd.) (Page 4 of 6 )
If either the mysql_connect or mysql_select_db commands fail, they $sConn or $dConn will contain no data. We use an if control to check for this, and if either one of them failed, we output document.write("Couldn't load news"); to the browser.
$nResult = mysql_query("select articleId, title from articles order by articleId desc limit 10");
Using the mysql_query function with a select statement returns the articleId and title fields for the ten most recent articles added to the articles table. The limit keyword takes care of making sure that only ten are returned.
There's nothing special about this while loop. It uses PHP’s mysql_fetch_array function to retrieve the next record from the $nResult resource and outputs a table row containing a hyper-linked news headline.
The actual URL of each headline is pointing to joe-bloggs-news.com/news.php and includes the id of the article tacked onto the end. You can change that URL to a script on your PHP server and display the news based on the value of the newsId query string value. That's outside the scope of this article, however.
Sample output for one of the news items using the while loop looks like this: