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>[email protected]</managingEditor>
                    <webMaster>[email protected]</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
https://forums.phpfreaks.com/topic/145539-phpmysql-rss/#findComment-764109
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.