MySQL
  Home arrow MySQL arrow Page 4 - Creating an RSS Reader: the Reader
FaxWave - Free Trial.
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
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? 
MYSQL

Creating an RSS Reader: the Reader
By: Jacques Noah
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2007-02-06

    Table of Contents:
  • Creating an RSS Reader: the Reader
  • XML-related Functions
  • The Meat of the Code
  • Reading RSS Data from a Database (Optional)

  • 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

    PCmover - $15 Off with Coupon Code CJPH7Q

    Creating an RSS Reader: the Reader - Reading RSS Data from a Database (Optional)
    (Page 4 of 4 )

    While it is good to have an RSS reader that can read any RSS document, it would be even better if you could store that information in a database and read it at your leisure when you are not connected to the Internet. It would also be good to be able to update your RSS file through the use of the database. It is relatively easy to achieve this, so let's create a table from which we will add our data:

    CREATE TABLE `rss_tbl` (

      `feed_id` int(5) NOT NULL auto_increment,

      `title` varchar(200) NOT NULL default '',

      `link` varchar(200) NOT NULL default '',

      `description` text NOT NULL,

      `the_date` date NOT NULL default '0000-00-00',

      PRIMARY KEY  (`feed_id`)

    ) TYPE=MyISAM AUTO_INCREMENT=1 ;

     The table will store the individual links as they are read in by the RSS reader. Fill this table with data, using the following format:

    • Title – the title of your story.
    •  Link – The link to your story.
    •  Description – A short description of your story.

    You can then use this data to write to your RSS file :

    <?

    $fp=fopen(“myrssfile”, “w+”);

    if (!$fp){

    echo “error opening file”;

    exit;

    }else{

    $query1="Select *,DATE_FORMAT(the_date,'%W,%d %b %Y') as thedate
    FROM rss_tbl WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) ORDER BY
    the_date DESC LIMIT 10 ";

    $result=mysql_query($query1);

    while($row=mysql_fetch_assoc($result)){

    fwrite($fp,$row[‘title’]."\r\n");

    fwrite($fp,$row[‘link’]."\r\n");

    fwrite($fp,$row[‘description’]."\r\n");

    fwrite($fp,$row[‘thedate’]."\r\n");

    fwrite($fp, ” ”);

    }//endwhile

    fclose($fp);

    }//end else

    This code does two things. First, it opens (or creates) a file called "myrssfile": 

    $fp=fopen(“myrssfile”, “w+”);

    The "w+" instructs PHP to create the file if it does not exist and to overwrite any contents that it might have. Then it checks to see if there are any problems opening the file: 

    if (!$fp){

    echo “error opening file”;

    exit;

     

    If there are problems, the program displays a message and stops execution. If every thing is okay, a SQL query is run that retrieves ten articles from the database that were created in the last thirty days: 

     $query1="Select *,DATE_FORMAT(the_date,'%W,%d %b %Y') as
    thedate FROM rss_tbl WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY)
    ORDER BY the_date DESC LIMIT 10 ";

    The DATE_FORMAT() function enables us to format the date column in what ever fashion we like. After this the code writes the database data to the file:

    fwrite($fp,$row[‘title’]."\r\n");

    fwrite($fp,$row[‘link’]."\r\n");

    fwrite($fp,$row[‘description’]."\r\n");

    fwrite($fp,$row[‘thedate’]."\r\n");

    fwrite($fp, ” ”);

    That’s it. A file called "myrssfile" should now be available and contain ten articles from the database. With small changes to the table you can expand the database usage and create an RSS aggregator, which is like a online "newspaper" that is entirely made up of RSS feeds from different websites.

    To actually enter the data into the database, you only need to create a form that will take the necessary input values and write them to the table. In one of the articles that I wrote about RSS, I discuss how to create and populate an RSS file through a form. Although in that particular article we transfer data from a form to a file, with some small changes you can transfer the data from a form to a database.

    Conclusion

    To use this code make sure to include “xmlparser.php” in whatever page you are using. Then just call the “parsefile(“yourRSSfileLocation”)” function and your file data will parsed. Also, you might have noticed that in some news sites, the news headlines are scrolling from right to left on the screen. You can achieve this by using the <marquee> HTML tag; Google it to find out how to use it.

    Download the xmlparser.php here. This is the same file we link to at the beginning of this article. Next, I will be discussing how to build a RSS File. Till then have fun.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hope you enjoyed my article. Any comments are very welcome
       · thank you for this tutorial,it's very detail and easy understand,but i think...
     

       

    MYSQL ARTICLES

    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...
    - Building a Search Engine with MySQL and PHP 5
    - Using Boolean Operators for Full Text and Bo...
    - PHP, MySQL and the PEAR Database
    - Working with PHP and MySQL
    - Getting PHP to Talk to MySQL
    - Creating an RSS Reader: the Reader
    - MySQL Security Overview
    - Creating the Admin Script for a PHP/MySQL Bl...
    - Creating the Blog Script for a PHP/MySQL Blo...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway