5, September 2008

Pulling info from database to fill in an RSS feed - working but I have a ? - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Pulling info from database to fill in an RSS feed - working but I have a ?
« previous next »
Pages: [1] Print

Author Topic: Pulling info from database to fill in an RSS feed - working but I have a ?  (Read 502 times)
My Name is Enigo Montoya
*
Posts: 33
188 credits
Members referred : 0


« on: Sep 11, 2007, 03:44:20 AM »

I am using a CMS system that stores data in MySQL, and I wanted to be able to fill in the RSS feed with the CMS pages.  I created rss.php which pulls the info from the database, sets some vars, and outputs the XML template...the problem is getting all the pages from the CMS system to display in the rss feed. (Currently only the Home page is displaying which is the first row in my table)

I got the idea from a blog script where it does just that...gathers all the blog postings(also stored in a database) and fills the XML template for the feed.  Looking into it further I found code that creates the multiple entries into the feed, but it was full of global vars and references to other functions thoughout the script.  Does anyone know of an easier way of doing this?

Code:
<?php // rss.php
/////////////////// connect to the database /////////////////////////////////////////////////////////

    
require_once('include/DbConnector.php');
    require_once (
'include/Validator.php');
    new 
DbConnector();

/////////////////// settings table //////////////////////////////////////////////////////////////////
    
$query "SELECT websiteName, websiteUrl, ownerEmail, id FROM settings"
$result mysql_query($query);    

$rows mysql_fetch_object($result);
{
$websiteName $rows->websiteName;  // variables we are getting from the "settings" table
$websiteUrl $rows->websiteUrl;
$ownerEmail $rows->ownerEmail;
}

/////////////////// category table //////////////////////////////////////////////////////////////////

    
$query "SELECT title, metaDesc, id FROM category"
$result mysql_query($query);

$rows mysql_fetch_object($result);
{
$title $rows->title;  // variables we are getting from the "category" table
$metaDesc $rows->metaDesc;
$id $rows->id;
}

    
$detail_url "$websiteUrl/index.php?id=$id";

/////////////////// send XML header //////////////////////////////////////////////////////////////////

header("Content-type: text/xml");

echo 
"<?xml version=\"1.0\" encoding=\"utf-8\"?>

<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\"
xmlns:dc=\"http://purl.org/dc/elements/1.1/\">
  <channel>
      <title>{$websiteName}</title>                                     
      <link>{$websiteUrl}/rss.php</link>                           
      <description>Updated information at {$websiteName}</description>   
      <language>en-us</language>
      <pubDate>{$pub_date}</pubDate> 
      <generator>{$websiteName} RSS</generator>                         
      <webMaster>{$ownerEmail}</webMaster>                               
<!-- BEGINBLOCK rss -->                                               
      <item>
         <title>{$websiteName} - {$title}</title>       
         <link>{$detail_url}</link>     
         <guid>{$detail_url}</guid>     
         <description>{$metaDesc}</description>   
         <pubDate>{$pub_date}</pubDate>
      </item>
<!-- ENDBLOCK -->                                                     
   </channel>
</rss>"
?>
Example XML output
Code:
<rss version="2.0">

<channel>
<title>Site Name</title>
<link>http://www.site.com/rss.php</link>
<description>Updated information at Site</description>
<language>en-us</language>
<pubDate/>
<generator>Site RSS</generator>
<webMaster>webmaster@site.com</webMaster>
<!-- BEGINBLOCK rss -->

<item>
<title>Site - Home</title>
<link>http://www.site.com/index.php?id=1</link>
<guid>http://www.site.com/index.php?id=1</guid>
<description>Site - description here</description>
<pubDate/>
</item>
<!-- ENDBLOCK -->
</channel>
</rss>

Any help is appreciated, thank you.
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Sep 11, 2007, 08:10:30 AM »

you need a loop to get the other records.

check while, or do... while loop types form the manual

just saw that the function "mysql_fetch_object" has the exact example


Last blog : Is your website is down? Know before your visitors do!
My Name is Enigo Montoya
*
Posts: 33
188 credits
Members referred : 0


« Reply #2 on: Sep 12, 2007, 04:17:09 AM »

Thank you for the reply, and suggestions Olaf.  Before I posted this I found some info on "while" loops here http://www.phpeasystep.com/mysql/6.html Visit through proxy but I must have had some things out of place.   I moved some things around, and now am able to pull all the table results to display them in HTML.  I used the same format to extract the data, and by using the following I can build my links to the pages
Code:
<? echo $rows['websiteUrl']; ?>/index.php?id=<? echo $rows['id']; ?>

So step one is down (pulling ALL the info from the database...now just parsing it into XML format).  I read today until my head hurt Grin I found some parsers that use "pear" which I know nothing about...and when I got home I went back to try the code from the blog script but it didn't work...all I got was

XML Parsing Error: no element found
Location: http://www.sitename.com/test.php/ Visit through proxy
Line Number 1, Column 1:
^
which is my opening <?php tag

So I searched again and found this http://agave.garden.org/~aaronh/php/txt2rss.html Visit through proxy but it takes the info from multiple text files that are uploaded and not a database so this doesn't serve my purpose of having the database update the XML file.  I also downloaded a class from phpclasses and then I notices posting of how others couldn't get it to work either.  I am farther along than I was, but now I am not having any luck...any ideas?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Sep 12, 2007, 08:43:02 AM »

you can use some project too, but you problem is more basic.

you should continue with the code that show your whole record set in the html


Last blog : Is your website is down? Know before your visitors do!
My Name is Enigo Montoya
*
Posts: 33
188 credits
Members referred : 0


« Reply #4 on: Sep 12, 2007, 11:05:16 AM »

you can use some project too, but you problem is more basic.

you should continue with the code that show your whole record set in the html
Nah that code was crap, and wouldn't have done anything.  I admit that I can't sit down and just right code in depth code full of fuctions from scratch, but if I have some in front of me as a start, I can normally spot patterns and piece things together.  Some are designers and some are programmers...and most of the time we can tell when a site has been designed by a programmer.  With programming phone lines in a switch all day, and going on very little sleep...I have resolved this issue.  XML works

At least I wasn't asking about MS Access, and how I could store my co-workers names and what department they work in...LOL  Cheesy  Cheesy

Thanks
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Sep 12, 2007, 11:10:54 AM »

come on... what you're trying is a beginners job, but it's up to you to learn somthing Wink


Last blog : Is your website is down? Know before your visitors do!
My Name is Enigo Montoya
*
Posts: 33
188 credits
Members referred : 0


« Reply #6 on: Sep 12, 2007, 11:29:02 AM »

How to echo hello world is a little more beginner than this. Wink  Yeah, some are here to learn and some are here to teach.  I won't post code because you probably already had 5 versions on how to do it.  That is the only way anyone can learn is by being persistant about what they want to do.   As always, I appreciate your ideas...it steps the thought process up a level.
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=7092
Tags : rss xml feed Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Pulling info from database to fill in an RSS feed - working but I have a ?
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Sep 05, 2008, 05:08:46 PM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 36.293
Total Topics: 7.476
Total Members: 3.899
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: speedy5044

34 Guests, 4 Users online :

15 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.