Connecting Tech Pros Worldwide Forums | Help | Site Map

RSS feeds with PHP and MySQL?

Zenbug
Guest
 
Posts: n/a
#1: Sep 6 '05
Does anyone have any good tutorials on how to create a dynamic RSS feed
that pulls data from a MySQL database using PHP? I found this one:
http://www.tiffanybbrown.com/article...article.php/66
....But I haven't quite been able to get it to work.

Thanks.
--ZenBug


Tim Van Wassenhove
Guest
 
Posts: n/a
#2: Sep 6 '05

re: RSS feeds with PHP and MySQL?


On 2005-09-06, Zenbug <zenbug@gmail.com> wrote:[color=blue]
> Does anyone have any good tutorials on how to create a dynamic RSS feed
> that pulls data from a MySQL database using PHP? I found this one:
> http://www.tiffanybbrown.com/article...article.php/66
> ...But I haven't quite been able to get it to work.[/color]

At first sight, the article seems pretty clear.
Might want to tell us where exactly you are having problems...

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>
Zenbug
Guest
 
Posts: n/a
#3: Sep 6 '05

re: RSS feeds with PHP and MySQL?


Okay -- I wanted to be sure the question was appropriate for this group
first...

Essentially, I've had to modify the code in order to get any results
When I view my generated RSS feed in an RSS reader, I see a series of
items that are all titled "No Title", and they all contain no content.
I do know that it must be connecting to the database in some way,
because there are as many RSS items as there are news items in my
database. So I guess it's having a problem pulling out actual field
values.

Thanks for the help.
Here's my code as it is now:

<?
header('Content-type: text/xml');
?>

<rss version="2.0">
<channel>
<title>My title</title>
<description>My description</description>
<link>www.mysite.com</link>
<copyright>copyright information</copyright>

<?
$dbh=mysql_connect ("localhost", "user", "pass") or die ('I cannot
connect to the database because: ' . mysql_error());
mysql_select_db ("myDatabase");

$getItems="SELECT id, title, news FROM news ORDER BY id DESC";
$doGet=mysql_query($getItems);

while($item=mysql_fetch_array($doGet))
{
$id=$doGet['id'];
$title=($doGet['title']);
$news=($doGet['news']);
?>

<item>
<title><?print $title;?></title>
<description><?print $news;?></description>
<link>http://www.littlepilgrims.ca/</link>
</item>

<? } ?>
</channel>
</rss>

Malcolm Dew-Jones
Guest
 
Posts: n/a
#4: Sep 6 '05

re: RSS feeds with PHP and MySQL?


Zenbug (zenbug@gmail.com) wrote:
: Okay -- I wanted to be sure the question was appropriate for this group
: first...

: Essentially, I've had to modify the code in order to get any results
: When I view my generated RSS feed in an RSS reader, I see a series of
: items that are all titled "No Title", and they all contain no content.
: I do know that it must be connecting to the database in some way,
: because there are as many RSS items as there are news items in my
: database. So I guess it's having a problem pulling out actual field
: values.

: Thanks for the help.
: Here's my code as it is now:

: <?
: header('Content-type: text/xml');
: ?>

: <rss version="2.0">
: <channel>
: <title>My title</title>
: <description>My description</description>
: <link>www.mysite.com</link>
: <copyright>copyright information</copyright>

: <?
: $dbh=mysql_connect ("localhost", "user", "pass") or die ('I cannot
: connect to the database because: ' . mysql_error());
: mysql_select_db ("myDatabase");

: $getItems="SELECT id, title, news FROM news ORDER BY id DESC";
: $doGet=mysql_query($getItems);

: while($item=mysql_fetch_array($doGet))
: {
: $id=$doGet['id'];
^^^^^^
: $title=($doGet['title']);
: $news=($doGet['news']);


Surely that should be $id=$item['id'], $title=$item['title'], etc.
^^^^^ ^^^^^

Off topic, but I think that <?php tags are prefered. All php servers
suport them, whereas <? only works on some servers, so it's a best habit
to simply use <?php and be done with it.



--

This programmer available for rent.
Zenbug
Guest
 
Posts: n/a
#5: Sep 7 '05

re: RSS feeds with PHP and MySQL?


You're right; there was an error in the tutorial. Seems to be working
now.
Thanks again everyone!
--ZenBug


Malcolm Dew-Jones wrote:[color=blue]
> Zenbug (zenbug@gmail.com) wrote:
> : Okay -- I wanted to be sure the question was appropriate for this group
> : first...
>
> : Essentially, I've had to modify the code in order to get any results
> : When I view my generated RSS feed in an RSS reader, I see a series of
> : items that are all titled "No Title", and they all contain no content.
> : I do know that it must be connecting to the database in some way,
> : because there are as many RSS items as there are news items in my
> : database. So I guess it's having a problem pulling out actual field
> : values.
>
> : Thanks for the help.
> : Here's my code as it is now:
>
> : <?
> : header('Content-type: text/xml');
> : ?>
>
> : <rss version="2.0">
> : <channel>
> : <title>My title</title>
> : <description>My description</description>
> : <link>www.mysite.com</link>
> : <copyright>copyright information</copyright>
>
> : <?
> : $dbh=mysql_connect ("localhost", "user", "pass") or die ('I cannot
> : connect to the database because: ' . mysql_error());
> : mysql_select_db ("myDatabase");
>
> : $getItems="SELECT id, title, news FROM news ORDER BY id DESC";
> : $doGet=mysql_query($getItems);
>
> : while($item=mysql_fetch_array($doGet))
> : {
> : $id=$doGet['id'];
> ^^^^^^
> : $title=($doGet['title']);
> : $news=($doGet['news']);
>
>
> Surely that should be $id=$item['id'], $title=$item['title'], etc.
> ^^^^^ ^^^^^
>
> Off topic, but I think that <?php tags are prefered. All php servers
> suport them, whereas <? only works on some servers, so it's a best habit
> to simply use <?php and be done with it.
>
>
>
> --
>
> This programmer available for rent.[/color]

Closed Thread