1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Php+rss

Discussion in 'PHP' started by gila, Nov 14, 2006.

  1. #1
    <? 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);
    SEMrush
    $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.
     
    gila, Nov 14, 2006 IP
    SEMrush
  2. skylark

    skylark Guest

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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
     
    skylark, Nov 14, 2006 IP
  3. gila

    gila Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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
     
    gila, Nov 14, 2006 IP
  4. gila

    gila Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Got any member can help me? urgent one...Thank You.
     
    gila, Nov 15, 2006 IP
  5. falcondriver

    falcondriver Well-Known Member

    Messages:
    963
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    145
    #5
    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.
     
    falcondriver, Nov 15, 2006 IP
  6. gila

    gila Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    How to use it?

    need modify anything?
     
    gila, Nov 16, 2006 IP
  7. falcondriver

    falcondriver Well-Known Member

    Messages:
    963
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    145
    #7
    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):
     
    falcondriver, Nov 16, 2006 IP
    TheGuy likes this.
  8. gila

    gila Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    After that how to run rss?

    TQ
     
    gila, Nov 16, 2006 IP
  9. falcondriver

    falcondriver Well-Known Member

    Messages:
    963
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    145
    #9
    you save his code as feed.php and link to it.
     
    falcondriver, Nov 17, 2006 IP
  10. gila

    gila Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    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.
     
    gila, Nov 19, 2006 IP
  11. vic_msn

    vic_msn Well-Known Member

    Messages:
    2,234
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    155
    #11
    vic_msn, Nov 19, 2006 IP
  12. gila

    gila Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    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
     
    gila, Nov 19, 2006 IP
  13. gila

    gila Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    - <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;
     
    gila, Nov 19, 2006 IP
  14. gila

    gila Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Got any person can help me?

    Thank You
     
    gila, Nov 20, 2006 IP
  15. gila

    gila Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    My link(URL) seens got problem, who can help me?
     
    gila, Nov 20, 2006 IP
  16. falcondriver

    falcondriver Well-Known Member

    Messages:
    963
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    145
    #16
    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"
     
    falcondriver, Nov 21, 2006 IP
  17. gila

    gila Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    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>
     
    gila, Nov 21, 2006 IP
  18. falcondriver

    falcondriver Well-Known Member

    Messages:
    963
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    145
    #18
    do you know what youre doing or is this just try&error?

    select ... CONCAT("http://merd.com/news.php?n=", news_id) AS url ...
     
    falcondriver, Nov 21, 2006 IP
  19. gila

    gila Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #19

    Hi, can u give me the full code?
     
    gila, Nov 21, 2006 IP
  20. gila

    gila Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #20
    $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......... :confused:
     
    gila, Nov 21, 2006 IP