<? header('Content-type: text/xml'); ?> <rss version="2.0"> <channel> <title>Mrd</title> <description>Freedom</description> <link>http://www.mrd.com</link> <copyright>2005 @ Mrd copyright</copyright> <? error_reporting( E_ERROR | E_WARNING | E_PARSE ); $User = ''; $Password= ''; $Host = ''; $DBName = ''; $link = mysql_connect ($Host,$User,$Password); @mysql_select_db($DBName, $link); $query = "SELECT * FROM news WHERE display = 1 ORDER BY postdate DESC LIMIT 0,10"; $result = mysql_query($query, $link); while( $row= mysql_fetch_array( $result ) ){ ?> <item> <title> <?=htmlentities(strip_tags($row['news'])); ?></title> <description> <?=htmlentities(strip_tags($row['desc'],'ENT_QUOTES'));?></description> <link>http://www.mrd.com/news.php?n=".$row['newsid']."</link> <pubDate> <?=strftime( "%a, %d %b %Y %T %Z" , $row['pubDate']); ?></pubDate> </item> <? } ?> </channel> </rss> I got problem on this script, who can help me? Thank You.
Hey gila, I spotted a few things that could solve your problem. The first one is I think you should add the line: <?xml version="1.0" encoding="ISO-8859-1" ?> just above the <rss version="2.0"> tag. I'd get rid of the <? header('Content-type: text/xml'); ?> line. I don't use it and my feed was validated using the service http://feedvalidator.org/. The second thing I recommend is replacing the line: <link>http://www.mrd.com/news.php?n=".$row['newsid']."</link> with <link>http://www.mrd.com/news.php?n=<?=$row['newsid'];?></link> The third fix would be to use the ENT_QUOTES constant for your item title tag as well. Just a tip, it's a good idea to get into the habit of specifically indicating the fields you wish to select in your query rather than using *. It'll improve your db's performance. Hope this helps! Skylark
Hi, i alreadly modify it: <? header('Content-type: text/xml'); ?> <?xml version="1.0" encoding="UTF-8" ?> <rss version="2.0"> <channel> <title>Mrd</title> <description>Freedom</description> <link>http://www.mrd.com</link> <copyright>2005 @ Mrd copyright</copyright> <?php error_reporting( E_ERROR | E_WARNING | E_PARSE ); $User = ''; $Password= ''; $Host = 'localhost'; $DBName = ''; $link = mysql_connect ($Host,$User,$Password); @mysql_select_db($DBName, $link); $query = "SELECT newid,topic,desc FROM news WHERE display = 1 ORDER BY postdate DESC LIMIT 0,10"; $result = mysql_query($query, $link); while( $row= mysql_fetch_array( $result ) ){ ?> <item> <title><?=htmlentities(strip_tags($row['topic'])); ?></</title> <description> <?=htmlentities(strip_tags($row['desc']));?></description> <link>http://www.mrd.com/news.php?n=<?=$row['newid'];?> </link> <pubDate> <?=strftime( "%a, %d %b %Y %T %Z" , $row['pubDate']); ?></pubDate> </item> <? } ?> </channel> </rss> but got this error Parse error: parse error, unexpected $end
hi there, i use the php rss creator. just include FeedCreator.class.php and insert your feed properties (title, lnk, description etc.): http://www.bitfolge.de/rsscreator-en.html oh, you have to create a folder "news" and give you script write-permission to this folder. rsscreator will cache the feed in his folder.
sure, see the example at http://www.bitfolge.de/rsscreator-en.html and change it like you want it: <? include("feedcreator.class.php"); $rss = new UniversalFeedCreator(); $rss->useCached(); $rss->title = "Mrd"; $rss->description = "Freedom"; $rss->link = "http://www.mrd.com"; $rss->syndicationURL = "http://www.mrd.com/".$PHP_SELF; // get your news items from somewhere, e.g. your database: $db = mysql_connect($dbHost, $dbUser, $dbPass); mysql_select_db($dbase); $res = mysql_query("SELECT newid,topic,desc FROM news WHERE display = 1 ORDER BY postdate DESC LIMIT 0,10"); while ($data = mysql_fetch_object($res)) { $item = new FeedItem(); $item->title = $data->title; $item->link = $data->url; $item->description = $data->short; $item->date = $data->newsdate; $item->source = "http://www.mrd.com"; $item->author = "John Doe"; $rss->addItem($item); } $rss->saveFeed("RSS1.0", "news/feed.xml"); ?> Code (markup):
jst above code: <? include("feedcreator.class.php"); $rss = new UniversalFeedCreator(); $rss->useCached(); $rss->title = "Mrd"; $rss->description = "Freedom"; $rss->link = "http://www.mrd.com"; $rss->syndicationURL = "http://www.mrd.com/".$PHP_SELF; // get your news items from somewhere, e.g. your database: $db = mysql_connect($dbHost, $dbUser, $dbPass); mysql_select_db($dbase); $res = mysql_query("SELECT newid,topic,desc FROM news WHERE display = 1 ORDER BY postdate DESC LIMIT 0,10"); while ($data = mysql_fetch_object($res)) { $item = new FeedItem(); $item->title = $data->title; $item->link = $data->url; $item->description = $data->short; $item->date = $data->newsdate; $item->source = "http://www.mrd.com"; $item->author = "John Doe"; $rss->addItem($item); } $rss->saveFeed("RSS1.0", "news/feed.xml"); ?> Code (markup): then what purpose for feedcreator.class.php ? Thank You.
Hi, Thank your replies. For now i got feed.php and and feed.xml. This 2 file got <titletitle> <description></description> <link></link> <dc:date></dc:date> above information but no any data, why? TQ
- <items> - <rdf:Seq> <rdf:li rdf:resource="2994" /> <rdf:li rdf:resource="2993" /> <rdf:li rdf:resource="2992" /> <rdf:li rdf:resource="2991" /> <rdf:li rdf:resource="2990" /> <rdf:li rdf:resource="2989" /> <rdf:li rdf:resource="2988" /> <rdf:li rdf:resource="2987" /> <rdf:li rdf:resource="2986" /> <rdf:li rdf:resource="2985" /> </rdf:Seq> </items> </channel> - <item rdf:about="2994"> <dc:format>text/html</dc:format> <dc:source>http://www.merd.com/news</dc:source> <dc:creator>emin</dc:creator> <title>why cannot display title</title> <link>2994</link> <description /> </item> Hi, i alreadly got data but the link got problem, the link show the number only not included URL. My source code: $item = new FeedItem(); $item->title = $data->topic; $item->link = $data->newsid; $item->description = $data->short; $item->date = $date->postdate; $item->source = "http://www.merd.com/news"; $item->author = $data->author;
you must change the sql so that it fits to your own database: $res = mysql_query("SELECT newid,topic,desc FROM news WHERE display = 1 ORDER BY postdate DESC LIMIT 0,10"); dont know your fieldnames, but you can easy adjust it with "AS": "SELECT my_id AS newid, my_topic AS topic, my_description AS desc FROM news WHERE display = 1 ORDER BY postdate DESC"
Oh..my select retrieve data from database correctly, just the url got problem only...... Actually my url should be like that: http://merd.com/news.php?n=3005 but that feed jst give me 3005 only $res = mysql_query("SELECT * FROM news WHERE display = 1 ORDER BY postdate DESC LIMIT 0,10"); $item = new FeedItem(); $item->title = $data->topic; $item->link = $data->newsid; $item->description = $data->desc; $item->date = $data->postdate; $item->source = "http://merd.com"; $item->author = $data->author; --------------------------------------------------------------------- <item rdf:about="3005"> <dc:format>text/html</dc:format> <dc:date>2006-11-21T07:26:52+01:00</dc:date> <dc:source>http://merd.com</dc:source> <dc:creator>emin</dc:creator> <title>Freedom on today</title> <link>3005</link> <description>xxxxxxxxxxxxxxxxxxxx<description> </item>
do you know what youre doing or is this just try&error? select ... CONCAT("http://merd.com/news.php?n=", news_id) AS url ...
$res = mysql_query("SELECT topic,concat(http://merd.com/news.php?n=, news_id) as url,desc,postdate,author FROM news WHERE display = 1 ORDER BY postdate DESC LIMIT 0,10"); while ($data = mysql_fetch_object($res)) { $item = new FeedItem(); $item->title = $data->topic; $item->link = $data->url; $item->description = $data->desc; $item->date = $data->postdate; $item->source = "http://www.merd.com"; $item->author = $data->author; $rss->addItem($item); } still got problem.........