Jump to content

PHP/MYSQL RSS


Andrew R

Recommended Posts

Here u some rss which i made. I hope that will help you.

 


<?php
  
  $host = "localhost";
  $database = "db";
  $user = "root";
  $password ="k" ;

$sqlcon = mysql_connect($host, $user, $password)
or die ("Can not connect to server");

mysql_select_db($database) 
or die ("Can not connect to database") ;

$query = "select * from news order by id desc limit 10  ";

$result = mysql_query($query, $sqlcon);


  while ($line = mysql_fetch_assoc($result))
        {
            $return[] = $line;
        }

$now = date("D, d M Y H:i:s T");

$output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
            <rss version=\"2.0\">
                <channel>
                    <title>MY RSS</title>
                    <link>http://www.site/rss.php</link>
                    <description></description>
                    <language>en-EN</language>
                    <pubDate>$now</pubDate>
                    <lastBuildDate>$now</lastBuildDate>
                    <docs>http://novosarajevo.ba</docs>
                    <managingEditor>you@youremail.com</managingEditor>
                    <webMaster>you@youremail.com</webMaster>";
            
foreach ($return as $line)
{   
    $title =  $line[title];
    $flash = $line[flash];
    $date=$line[year]."-".$line[month]."-".$line[day];
    
    $condate = date("D,j M Y", strtotime($date));
    $time =$line[ 'time'];
    $time = explode(":", $time);
    $conhour=$time[0]-2;
$contime = $conhour.":".$time[1].":".$time[2];
$output .= "<item> 
                    <title>".$title."</title>
                    <link>http://site.com?pid=".htmlentities($line['id'])."</link>
                    <description>".$flash."</description>
                    <pubDate>".$condate." ". $contime." +0000 </pubDate>

                </item>";
}
$output .= "</channel></rss>";

echo $output;


?>




Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.