JavaScript
  Home arrow JavaScript arrow Page 3 - Revisited: Creating an XML Content Feed Wi...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Revisited: Creating an XML Content Feed With PHP
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 7
    2002-10-28

    Table of Contents:
  • Revisited: Creating an XML Content Feed With PHP
  • Why a content feed?
  • Creating a sample content feed
  • Creating a sample content feed (contd.)
  • Testing Our Content Feed
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Revisited: Creating an XML Content Feed With PHP - Creating a sample content feed


    (Page 3 of 6 )

    One of the reasons why content feeds are so popular is that because 99% of the time, all you need to do to add someone elses content feed to your site is add a reference to an external JavaScript file using a HTML <script> tag, like this:

    <script language="JavaScript" src="http://www.joe-bloggs-news.com/feed.php">

    Let's assume that I run a small web site and want to publish Joe Blogg’s content feed on my site using the code above. In it, I've set the src attribute to a file named feed.php on Joe's web site (and not a typical JavaScript file that ends with .js).

    This isn't a problem, however, because both IE and Netscape don't care what the file extension is, just as long as when the file is grabbed, it actually contains valid JavaScript code. Let's create a sample content feed now. To start with, load the MySQL console application and create a new database named content:

    create database content;

    use content;


    Next, create a new table named articles. This table will contain all of our news items:

    create table articles

    (

    articleId int auto_increment not null,

    title varchar(100),

    content text,

    primary key(articleId),

    unique id(articleId)

    );


    The table we've just created should be pretty self-explanatory. It contains three fields: articleId, an integer which is also a primary key and unique identifier. Title, which will contain the headline of each news item, and content, which is a text field that will contain the body of our news item.

    Let's add three news items to our articles table using the following MySQL commands:

    insert into articles values(0, 'PHP scripting language takes world by storm', 'It was announced today that at least two million web sites around the world are using the PHP and MySQL language/databasing technique to create sites that are flexible');

    insert into articles values(0, 'Linux includes G++ compiler', 'Linux, one of the worlds most popular operating systems also includes a copy of both the GCC and G++ compilers, which allow you to compile C/C++ program easily from the command line');

    insert into articles values(0, 'Microsoft announces C#', 'Microsoft have today announced that its new .NET framework will be based around a language named C# (pronounced C-Sharp). This language is much like C++ but designed for moder n prorgammers');


    Next, we want to create the PHP script that will retrieve the news from our MySQL database and output it to the browser so that it appears as a bunch of JavaScript code. The PHP scripts name is feed.php and it is available for download here. We will concentrate only on the more important aspects of the script.

    $db_server = "localhost";

    $db_db = "content";

    $db_user = "admin";

    $db_pass = "password";


    Our script starts of by creating four variables which will be used to login to our MySQL server. I'm assuming that MySQL is installed on the same machine as where the feed.php script will be setup.

    @$sConn = mysql_connect($db_server, $db_user, $db_pass);

    @$dConn = mysql_select_db($db_db, $sConn);

    if(!$sConn || !$dConn)

    {

    ?>

    document.write("Couldn't load news");

    <?php

    }

    More JavaScript Articles
    More By Mitchell Harper


     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT