php Form.net

Free PHP forms, scripts, resources and tutorials.

MySQL – Select from two tables

Example:
config.php

<?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 (mysql_error());
endif;
?>
rss.php

<?php header('Content-type: application/rss+xml'); ?>
<?php echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>example.com</title>
<description>news example.com</description>
<link>http://example.com</link>
<?php
include ('config.php');
$res = mysql_query("SELECT id, title, description, date  
FROM news ORDER by date DESC LIMIT 5"
)
or die(mysql_error());
while($row = mysql_fetch_array($res)){
?>
<item>
<title> <?php echo $row['title']; ?></title>
<description> <?php echo htmlspecialchars($row['description'], ENT_QUOTES); ?> </description>
<link>http://example.com/?id=<?php echo $row['id']; ?></link>
<guid>http://example.com/<?php echo $row['id']; ?>.html</guid>
<pubDate> <?php echo date("r", strtotime($row["date"])); ?></pubDate>
</item>  
<?php
}
?>

Comments


Add a Comment

Name:


Comment:




Sponsors



Google Meta Tags Generator Online
Create your own meta tags using our free code generator.

BuzzBoost Css Generator Online
Free Google BuzzBoost CSS Style Generator Online

Text Ads Generator
Create Your Own HTML Ad Using Our Free HTML Editor

Link Style Generator
Free CSS Style Sheet Generator for Links

CopyRight phpForm.net