rss feed script

Discussion in 'PHP' started by irdogg, Dec 6, 2010.

  1. #1
    im getting an error and it wont show items
    <b>Warning</b>:  mysql_fetch_object(): supplied argument is not a valid MySQL result resource in <b>/usr/home/public_html/rss.php</b> on line <b>64</b><br />
    
    Code (markup):
    Help! :eek:
    
    <?php
    ################################################
    #                                              #
    #  SRSSS - Simple RSS Script                   #
    #  Version 1.5 - 2007-02-11 Florian Beer       #
    #                                              #
    #  Dieses Script steht unter der MDWDW Lizenz. #
    #  Die 'Mach doch was du willst' Lizenz.       #
    #  Viel Spass damit!                           #
    #                                              #
    ################################################
    
    // RSS Setup
    $title            = 'My Homepage';
    $link            = 'http://www.myhomepage.com';
    $description     = 'This is the feed from my homepage';
    $encoding        = 'iso-8859-1';
    $lang            = 'de-at';
    
    // DB Setup
    $host             = "localhost";
    $user             = "root";
    $pass             = "";
    $db                = "myDBname";
    $query             = "SELECT * FROM quotes ORDER BY ID DESC LIMIT 10";
    
    $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
    mysql_select_db($db, $connection) or die ("Unable to select database!");
    $result = mysql_query($query);
    
    function convTimestamp($date){
        $year   = substr($date,0,4); 
        $month  = substr($date,4,2); 
        $day    = substr($date,6,2); 
        $hour   = substr($date,8,2); 
        $minute = substr($date,10,2); 
        $second = substr($date,12,2); 
        $stamp =  mktime($hour, $minute, $second, $month, $day, $year);
        return $stamp; 
    }
    
    header('Content-type: application/rss+xml');
    echo '<?xml version="1.0" encoding="'.$encoding.'"?>';
    echo "\n";
    echo '<rss version="2.0">';
    echo "\n";
    echo '<channel>';
    echo "\n";
    echo "\n";
    echo '<title>'.$title.'</title>';
    echo "\n";
    echo '<link>'.$link.'</link>';
    echo "\n";
    echo '<description>'.$description.'</description>';
    echo "\n";
    echo '<lastBuildDate>'.date("D, d M Y H:i:s").' +0000</lastBuildDate>';
    echo "\n";
    echo '<language>'.$lang.'</language>';
    echo "\n";
    echo "\n";
    
    // Loop through all items
    // substitute with your DB values
    while($row = mysql_fetch_object($result)){
    $stamp = convTimestamp($row->timestamp);
    echo '<item>';
    echo "\n";
    echo '        <title>'.$row->title.'</title>';
    echo "\n";
    echo '        <link>'.$link.$row->ID.'</link>';
    echo "\n";
    echo '        <guid>.'$link.$row->ID.'</guid>';
    echo "\n";
    echo '        <pubDate>'.date("D, d M Y H:i:s", $stamp).' +0000</pubDate>';
    echo "\n";
    echo '        <description>'.$row->text.'</description>';
    echo "\n";
    echo '</item>';
    echo "\n";
    }
    
    echo "\n";
    echo '</channel>';
    echo "\n";
    echo '</rss>';
    ?> 
    Code (markup):

     
    irdogg, Dec 6, 2010 IP
  2. drctaccess

    drctaccess Peon

    Messages:
    62
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #2
    the line below is wrong
    
    echo '        <guid>.'$link.$row->ID.'</guid>';
    
    Code (markup):
    it should be
    
    echo '        <guid>'.$link.$row->ID.'</guid>';
    
    Code (markup):
    except this... if you have that table called quotes and the proper fields in that table.. then it should work.

    I hope this one helps
     
    drctaccess, Dec 6, 2010 IP
  3. irdogg

    irdogg Well-Known Member

    Messages:
    358
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    135
    #3
    still won't pull items and that errors is there i give up thanx anyway.
     
    irdogg, Dec 6, 2010 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    I was going to say its the query, I think you need to do it this way.

    $result = mysql_query("$query");

    Or if that's still falling just write it out:

    $result = mysql_query("SELECT * FROM quotes ORDER BY ID DESC LIMIT 10");
     
    Last edited: Dec 6, 2010
    MyVodaFone, Dec 6, 2010 IP
  5. imocoder

    imocoder Member

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #5
    Perhaps you should transmit MySQL connection link identifier toward mysql_query:

    
    $result = mysql_query($query);
    
    Code (markup):
    Change to:
    
    $result = mysql_query($query, $connection);
    
    Code (markup):
    Let us know if it helped you.
     
    imocoder, Dec 7, 2010 IP