PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Francesco Cirać   Query2RSS   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Usage Example
Class: Query2RSS
Generate RSS feeds from MySQL query results
Author: By
Last change:
Date: 14 years ago
Size: 837 bytes
 

Contents

Class file image Download
<?php
// Suppose there is a database connection section here.
// Suppose we have a "news" table with "title" and "content" fields.

// Step 1: Include Query2RSS class file in order to use it.
include_once "query2rss.class.php";

// Step 2: Initialiting our feed with the feed title, link and description.
$feed = new Query2RSS("Example Feed", "http://example.com", "An example RSS 2 feed");

// Step 3: Setting a custom feed property.
$feed->custom("language","en-us");

// Step 4: Fetching the last 5 news from the database.
$datas = mysql_query("SELECT * FROM news LIMIT 5");

// Step 5: Mapping the query fields to the right feed elements.
$feed->fieldmap("title", "title");
$feed->fieldmap("content", "description");

// Step 6: Generating and printing the feed with our query.
echo $feed->generate($datas);
?>