Ad block is installed and active. Please support us by disabling it.
HomeThursday, September 21, 2017, 03:23:10
1

RSS, MySQL & Smarty

Tuesday, February 10, 15, 00:32:33, 3 Yaers Ago Via wain, Hits: 2502
Smarty > Publishing MySQL Data in RSS 2.0
config.php

Code:
<?php
$dbhost = 'localhost';
$dbusername = 'root';
$dbpassword = 'mydbpass';
$dbname = 'test';
$conn=mysql_connect($dbhost, $dbusername, $dbpassword);
if(!$conn) :
die('Could not connect: ' . mysql_error());
endif;
$db=mysql_select_db($dbname, $conn);
if(!$db) :
die ('Can't connect to database : . mysql_error());
endif;
?>


rss.php

Code:
<?php
//database connection
include_once('config.php');
include('smarty/Smarty.class.php');
$smarty = new smarty();
$smarty->template_dir = 'templates';
$smarty->compile_dir = 'templates_c';
$smarty->config_dir = 'config';
$smarty->cache_dir = 'cache';
?>
<?php header('Content-type: application/rss+xml'); ?>
<?php echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; ?>
<?php
$res = mysql_query("SELECT * FROM news ORDER by id DESC LIMIT 20")
or die(mysql_error());
while($row = mysql_fetch_array($res)){
$value[] = $row;
}
$smarty->assign('news', $value);
$smarty->caching = 1;
$smarty->display('rss.tpl');
?>


templates/rss.tpl

Code:
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Example.com</title>
<description>Example WebSite</description>
<link>http://www.example.com</link>
{section name=news loop=$news}
<item>
<title>{$news[news].title|stripslashes|truncate:50} :: Example.com</title>
<description>{$news[news].text|stripslashes|escape:'html'}</description>
<link>http://www.example.com/page.php?id={$news[news].id}</link>
<guid>www.example.com/page.php?id={$news[news].id}</guid>
<pubDate>{$news[news].date|date_format:"%a, %e %b %Y %H:%M:%S"} GMT</pubDate>
</item>
{/section}
</channel>
</rss>

Sign In

Sponsor

Related

Preventing multiple form submissions

Preventing multiple form submissions

PHP $_GET Function

Get function in PHP

Link Base 2.0.

Manage your links using a MySQL database. It features easy install, user submission, and an admin panel to add, edit and remove categories and links.

Sitemap

phpForm.net Website Sitemap

ShoutBox 1.1. PHP Script

ShoutBox allows your users to post short messages on your site. The script is lightweight and very easy to install and use.

Creating a CAPTCHA with PHP with imagecreate

This tutorial will show you how to create a form with Captcha, Requirement(s): PHP Server, GD Graphics Library

PHP $_SESSION

Session_start creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie.

Upload File with PHP

Basic file uploading with PHP

PHP Cookies - setcookie

Defines a cookie to be sent along with the rest of the HTTP headers.

Process Form Data with Jquery

jQuery, Process form data
About Author

wain

Date Registered: Sun, Feb 8, 15
Last Time Online: Thu, Jun 15, 17
So far has created 115 entries.
wain
This author has not yet filled in any details.