RSS Feed coding

software development

#1

I’m attempting to create an rss feed for my site. I’ve created an .xml document that checks out o.k. with feed validators except for one crucial section:

: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
/home/.lamour/murphycl/murphy-clan.org/rssnews.xml
on line
19

For the life of me, I’ve only got 39 lines in my .xml file, but I cannot determine where I am going wrong. Below is the entire file. Can anyone help me figure out where my code is off? I suspect it’s the sql statement, but I’m not that bright: it might be something else.

<? mysql_select_db($database_*******, $*******); $getItems="SELECT news_id, news_head, news_body, news_update, UNIX_TIMESTAMP(news_date) AS pubDate FROM ******* LIMIT 1 ORDER BY pubDate DESC"; $doGet=mysql_query('$getItems'); while($item=mysql_fetch_array($doGet)) { $id=$doGet['news_id']; $title=strip_tags($doGet['news_head']); $body=strip_tags($doGet['news_body']); $body=substr($doGet['news_body']); $pubDate=strftime("%a, %d %b %Y %T %Z",$doGet['pubDate']); ?> <?print htmlentities($title, 'ENT_QUOTES');?> <?print htmlentities($body, 'ENT_QUOTES');?> http://www.********.org/news_search.php?news_id=<?print $id;?> <? } ?>

Any help is greatly appreciated.

Thank you,
Max


#2

If that’s all your file then you’ve not actually connected to the database?

Also your 4th line should be (this is the error)

$doGet=mysql_query($getItems);

remove the single quotes. Using single quotes means that anything in those quotes will be intrepted as is. ie it will not evaluate variables (eg $getItems). Using double quotes " tries to evaluate the variables.

Not sure if it matters that much in xml but you should remove the blank lines before and after the break php tags ?> <?php


#3

I didn’t mention it before, but I excluded the database connection code intentionally. It is a part of the file. Sorry for the confusion.

Thanks for your feedback, decs. I did remove the single quotes, but the error persists. Could this have anything to do with server configuration? I have an .htaccess file parsing .xml as .php.

That’s all I got.


#4

Which line is line 19 then?


#5

It is the

while($item=mysql_fetch_array($doGet))

you addressed in your last post. Even without the single quotes, the error points to that phrasing, specifically.


#6

Are there rows in the table? Try removing the unix_timestamp from the sql. Other than that I’m stumped :frowning:


#7

Yes, the table has rows and is populated. I’ll try removing the timestamp and see what happens.

Thanks for sticking with me, decs. I appreciate your input. If at some point I figure out a solution, I’ll post it here.


#8

I don’t know if it is helpful to you, but I thought I’d share my own method of creating an RSS feed. I actually create a file, and then each time I make an update I simply delete the file and create it again. It may not be the best solution, but at the time it was quite logical, given my then lack of PHP expertise. Here’s the code:

[code]// get feed data
$sql = “select id, unix_timestamp(timestamp) as timestamp, unix_timestamp(modified) as modified, title, abstract, slug
from entries
order by id desc
limit 10”;
$rss = mysql_query($sql,$link) or die(“

Could not retrieve RSS data: “.mysql_error().”

\n”);

// re-create RSS feed
if(file_exists("…/blog/rss.xml")) {
unlink("…/blog/rss.xml");
}
touch("…/blog/rss.xml");
$fp = fopen("…/blog/rss.xml", “w”) or die(“Couldn’t open rss.xml”);
fwrite($fp, “<?xml version=\"1.0\" ?>\n”);
fwrite($fp, “<rss version=“2.0”>\n”);
fwrite($fp, " \n");
fwrite($fp, " si-blog\n");
fwrite($fp, " The personal web log of Simon Jessey, website designer and web standards evangelist.\n");
fwrite($fp, " en\n");
fwrite($fp, " Copyright “.date(“Y”).” Simon Jessey\n");
fwrite($fp, " http://jessey.net/blog/\n");
while($row = mysql_fetch_array($rss)) {
$timestamp = $row[‘timestamp’];
$date = timestamp_to_url($timestamp);
$rss_date = gmdate(“r”, $timestamp);
$title = $row[‘title’];
$abstract = $row[‘abstract’];
$slug = $row[‘slug’];
$link = “http://jessey.net/archive/$date/$slug/”;
fwrite($fp, " \n");
fwrite($fp, " $title\n");
fwrite($fp, " $abstract\n");
fwrite($fp, " $link\n");
fwrite($fp, " $rss_date\n");
fwrite($fp, " \n");
}
fwrite($fp, " \n");
fwrite($fp, “\n”);
fclose($fp);[/code]
It is worth noting that this feed only produces a summary. I prefer not to provide full texts with my feeds.

Simon Jessey
Keystone Websites | si-blog


#9

Thanks for the code sample! I think having a summary feed is a great idea. The .xml file I have been troubleshooting in this thread is for a full-text, individual news item feed.

As an aside, I am an idiot. I just noticed I had properly declared the mysql connection and database, but I did not include a table name for the query. That might help.

It’s always the most obvious, basic thing that holds everything else up. I’ll check it later today, but I’m betting that will remedy my feed.


#10

I would also like to point out:

The error you’re getting means that $doGet did not return any results and the main reason for this is quite simple; You’re using Single Quotes (’) around your variable.

Remove the quotes and do some real error checking before assuming $doGet isn’t null.


#11

guice, thanks for jumping in, here. You are correct: the single quotes needed to go. I have made those changes, but the error persists.

I hadn’t considered that a null set for $doGet could produce the error. However, that possibility opens up a whole new can of worms, i.e. the query isn’t grabbing records (for any number of reasons.) I’ve been combing this for a few weeks now. Any other input you have on this is greatly appreciated.


#12

print $getItems . “\n”;

See what you get and run that manually. See if mysql_errno() or mysql_error() have anything set.


#13

“See what you get and run that manually. See if mysql_errno() or mysql_error() have anything set.”

That would have been the sensible advice to give! Silly me ^_^;