Jump to content


Photo

RSS feed from MySql with php


  • Please log in to reply
4 replies to this topic

#1 dpiearcy

dpiearcy

    Advanced Member

  • Members
  • PipPipPip
  • 83 posts

Posted 27 January 2013 - 08:48 PM

This may be off topic here but it DOES contain php so....

I'm creating an XML for an RSS feed. For some reason the loop isn't working. It only shows me the last post, not the LIMIT 10. But if I run it through feedvalidator.org I see all 10. Just not in Mac Mail which I use to read RSS feeds. (just remembered after pasting the code I removed the LIMIT 10 while testing so ignore that above).

Any thoughts? The loop looks fine to me. And it's showing in the validator.

Or a better way of achieving this would be awesome too.

$rssfeed = '<?xml version="1.0" encoding="ISO-8859-1"?>';
    $rssfeed .= '<rss version="2.0">';
    $rssfeed .= '<channel>';
    $rssfeed .= '<title>My Site Feed</title>';
    $rssfeed .= '<link>http://www.mysite.com</link>';
    $rssfeed .= '<description>News feed</description>';
    $rssfeed .= '<language>en-us</language>';
    $rssfeed .= '<copyright>Copyright (C) 2013 mysite.com</copyright>';
 
    $connection = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
        or die('Could not connect to database');
    mysql_select_db(DB_NAME)
        or die ('Could not select database');
 
    $query = "SELECT * FROM table ORDER BY date DESC";
    $result = mysql_query($query) or die ("Could not execute query");
 
    while($row = mysql_fetch_array($result)) {
        extract($row);
 
        $rssfeed .= '<item>';
        $rssfeed .= '<title>' . $title . '</title>';
        $rssfeed .= '<description>' . $description. '</description>';
        $rssfeed .= '<link>http://www.mysite.php</link>';
        $rssfeed .= '<pubDate>' . date("D, d M Y H:i:s O", strtotime($date)) . '</pubDate>';
        $rssfeed .= '</item>';
    
 }
    $rssfeed .= '</channel>';
    $rssfeed .= '</rss>';
 
    echo $rssfeed;

Thanks

#2 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 27 January 2013 - 09:02 PM

But if I run it through feedvalidator.org I see all 10. Just not in Mac Mail which I use to read RSS feeds.


Sounds like the issue is your feed reader. How does it look in Google Reader?


My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#3 dpiearcy

dpiearcy

    Advanced Member

  • Members
  • PipPipPip
  • 83 posts

Posted 27 January 2013 - 09:08 PM

You were right "sweetheart" ;-) (sorry...couldn't resist).

Shows up just fine in google reader. Talk about making Steve Jobs roll over. He hated and wanted to destroy google and here they are reading it correctly and his mail program is not.

Thanks for pointing me to google. Did not know they had this. Who has time to actually surf the net these days anyway?

#4 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 27 January 2013 - 09:31 PM

It's probably some settings you have. Usually when you first subscribe to a feed, the reader doesn't show you too many posts. Like google will always only show you the 10 most recent posts in the past, then all new ones as they appear. Try subscribing, then publishing some new posts, like 2 or 4 of them, and see if your mac feed reader shows all the new ones. 


My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#5 dpiearcy

dpiearcy

    Advanced Member

  • Members
  • PipPipPip
  • 83 posts

Posted 27 January 2013 - 09:39 PM

It's probably some settings you have. Usually when you first subscribe to a feed, the reader doesn't show you too many posts. Like google will always only show you the 10 most recent posts in the past, then all new ones as they appear. Try subscribing, then publishing some new posts, like 2 or 4 of them, and see if your mac feed reader shows all the new ones.


I will try that. Wasn't really wanting it for the feeder in my mac mail though. Just making sure it was getting all the info I needed for my HTML5 app. Need that populated correctly for that app. So I doubt I'll mess with my reader. I don't really subscribe to stuff anyway but this seemed like the easiest way to populate the fields on the webpage to the app since I'm already populating the page from MySql info.

And this is a specialized application they don't want to pay apple to put in the app store so no objective C and Xcode on this one.

Thanks again!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com