Help - Search - Members - Calendar
Full Version: RSS Feed: The XML page cannot be displayed
Codegrrl.com Forums > Script Help > Tutorial Help
Kurisutaru
From the opening of my site I have been looking for an easy way to handle an RSS feed, but none of the options out there don't seem very practical or easy to use. And the last one I tried refused to display any new updates, only old ones.
So seeing this one here, small and simple, I have high hopes..

But I can't for the life of me get the RSS feed script to run on my site.
I have a working database that my site updates are posted though, and it also has the ID setup already the same way the tutorial said it needed to be, I've gone though and edited the title and entry values to match the ones my update script uses (topic and post), aside from that and putting in my data, the script is unedited, but it still returns an error.

QUOTE
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
Only one top level element is allowed in an XML document. Error processing resource
<b>Warning</b>: mysql_connect(): Unknown MySQL Server Host '$dbhost' (0) in <b>/home/memoirs/www/rss.php&...

The last part confuses me, server host is localhost, all my database scrips use that, so yes I do know that for sure.
The rest of the info is also correct, password, database name, etc.
I have double checked and even started fresh, even tweeked it to run off my sites news config file that holds the database information already, but the error still does not change.


I'm also a little confused on the
$permafile = "entry.php";
part. Where is that to point to? My news.php that is just the news and included to my sites main page, or my site index? Right now I have it set to my news.php file.

Also one more small thing I am conserned with, I have news that is submitted to the database that is not yet made 'public'. As I make updates I write them down so I don't lose track or forget what I had messed with, as most the updates I make span a few days or weeks at times. And save that in the database, when it's all done with I set the post to public for all to see.

Will this display those hidden submissions in the feed as well?
loadx
Looks like your xml file isnt valid, post a link to it and ill have a peek.

The mysql error looks maybe like you've simply quoted the var e.g
'$foo' instead of $foo
Kurisutaru
QUOTE(loadx @ Jan 11 2007, 11:59 PM) *

Looks like your xml file isnt valid, post a link to it and ill have a peek.

The mysql error looks maybe like you've simply quoted the var e.g
'$foo' instead of $foo



How can it not be valid if it's using the same tutorial from here and just connecting to my database?

rss.php

CODE
<?php
header ("Content-Type: text/xml");
echo '<?xml version="1.0" encoding="ISO-8859-1" ?>';
########################################################################
### editable stuff begins here #########################################
$sitename = "test";# The Name of your website
$sitedesc = "testing the feed";# a description of your website
$siteurl = "http://www.test.com";# don't forget the http://, NO trailing slash!
$permafile = "news.php"; # the name of the file where your permanent link is directed (which displays only the single entry)


$table = "news";# the name of the table you want to use for this
$dbhost = "localhost";# Your database host (usually localhost)
$dbname = "******";# Name of the datebase you'd like to use
$dbuser = "******";# Your database username
$dbpass = "******";# Your database password
### end of editable stuff, proceed with care ##########################
#######################################################################
mysql_connect ('$dbhost', '$dbuser', '$dbpass');
mysql_select_db ('$dbname');

$query = "SELECT * FROM $table ORDER BY timestamp DESC LIMIT 10";
$res = mysql_query($query);
$num = mysql_num_rows($res);

echo "<rss version=\"2.0\">\n";
echo "<channel>\n";
echo "<title>$sitename</title>\n";
echo "<link>$siteurl</link>\n";
echo "<description>$sitedesc</description>\n";

  while($row = mysql_fetch_assoc($res)) {
$id = $row["id"];
$date = date("D, d M Y H:i:s O",$row["timestamp"]);
$title = htmlentities(strip_tags($row["topic"]), ENT_QUOTES);
$entry = htmlentities(strip_tags($row["post"]), ENT_QUOTES);

if (strlen($entry) > 500)
{
$entry = substr($entry,0,500);
$entry = "$entry...";
}
    echo "<item>\n";
    echo "<title>$title</title>\n";
    echo "<link>$siteurl/$permafile?id=$id</link>\n";
    echo "<description>\n";
    echo "$entry";
    echo "</description>\n";
echo "<pubDate>$date</pubDate>\n";
    echo "</item>\n";
  } # close the while loop
echo "</channel>\n";
echo "</rss>\n";
?>
Amelie
Please note that the tutorial was written by one of our members and I don't think it's been fully tested before.
Kurisutaru
QUOTE(Amelie @ Jan 13 2007, 02:01 PM) *

Please note that the tutorial was written by one of our members and I don't think it's been fully tested before.


Then I guess I'll have to give up on finding a RSS feed. I have only found one script that worked but it didn't output valid code.
Jem
If you tell me your database structure, I could probably knock you up an RSS feed smile.gif
loadx
QUOTE

mysql_connect ('$dbhost', '$dbuser', '$dbpass');
mysql_select_db ('$dbname');


change to
CODE

mysql_connect ($dbhost, $dbuser, $dbpass);
mysql_select_db ($dbname);


you are sending it string literal, no wonder it's not connecting tongue.gif
Jem
^ That's what I assumed, but there's no point correcting just those bits because there are other errors ($row["topic"] instead of $row['topic'], $num = mysql_num_rows($res); doesn't seem to do anything/isn't related to anything..)

I would have thought it sensible to make it mandatory to actually test the tutorials before they're uploaded.
loadx
you would think so, yeah.
Amelie
$row["topic"] and $row['topic'] can both be used. It doesn't really matter which style of quotes is used... I tend to use the single quotes for array data and double quotes for strings, but some like the double quotes for everything.

As for the tutorials, those can only be seen by Sasha and Vixx before they are approved, so I suppose it is up to them to test them...
Jem
QUOTE(Amelie @ Jan 15 2007, 09:09 PM) *

$row["topic"] and $row['topic'] can both be used.

Actually, you should only use $row['topic'] for accessing data in arrays unless there's a variable in there ($row["$variable"]). It's just good coding practise; you and I both know that.

QUOTE(Amelie @ Jan 15 2007, 09:09 PM) *

As for the tutorials, those can only be seen by Sasha and Vixx before they are approved, so I suppose it is up to them to test them...

I don't think it is, as I'm sure they've got far more important things to do. I think the people writing the tutorials should thoroughly test them first.
loadx
in my opinion $foo["$blah"] is dogpoo.. you are using a fraction more load because it's casting the var and the php interpretor see's it in quotes therefore thinks it's a string initially then again see's the $ and realises the var needs to be interpreted.

here's a benchmark of $foo["$bar"]
1 = 0.99802328742515
2 = 0.99802113572854
3 = 0.99802137824351


and $foo[$bar]
1 = 0.99802184830339
2 = 0.99801991616766
3 = 0.99802010778443

not a great deal of difference..and thats over an array A,Z with 1000 iterations picking a rand(0,25).

However it's still one extra step that doesnt need to be taken and putting quotes around things implies it's either part of a string or is a string...why double cast it?

CODE

for anyone who cares for the bench code..used globals so passing time was irrelevant. PEAR :: Benchmark is used. This deomstrates the against argument and i just modified code for the for argument.. too lazy to write 2 sections :D

  require_once 'Benchmark/Profiler.php';
  require_once 'Benchmark/Iterate.php';
  
    $rand = rand(0,25);
    $foo = array(range('a','z'));
      
      $profiler = new Benchmark_Iterate;
    
      function myFunction(){
         
        global $foo;
        global $rand;
        
        echo $foo[$rand];    
        return;
     }

    
     $profiler->run(1000, 'myFunction', '');
     $result = $profiler->get();
     echo "1 = ".average($result).'<br />';
    
     $profiler->run(1000, 'myFunction', '');
     $result = $profiler->get();
     echo "2 = ".average($result).'<br />';
    
     $profiler->run(1000, 'myFunction', '');
     $result = $profiler->get();
     echo "3 = ".average($result).'<br />';
    
    
    


function average($arr)
{
   if (!is_array($arr)) return false;

   return array_sum($arr)/count($arr);
}
Amelie
QUOTE(Jem @ Jan 16 2007, 09:27 AM) *

QUOTE(Amelie @ Jan 15 2007, 09:09 PM) *

$row["topic"] and $row['topic'] can both be used.

Actually, you should only use $row['topic'] for accessing data in arrays unless there's a variable in there ($row["$variable"]). It's just good coding practise; you and I both know that.


True. However, some people just like doing things in different ways, whether those ways are "correct" or not. I tend to use double quotes for strings that don't contain variables even though I know that it is better to use single quotes. It's just the way I prefer it... *shrug*
Jem
QUOTE(Amelie @ Jan 16 2007, 07:06 PM) *

However, some people just like doing things in different ways, whether those ways are "correct" or not.

Since when do you advocate that nonsense? I've seen you scoffing at people who say that in regards to HTML validation before! tongue.gif
Kurisutaru
So has anyone been able to get this working at all? It looks like there are a load of errors in the script.
Jem
Did you miss this one? smile.gif
QUOTE(Jem @ Jan 14 2007, 12:50 PM) *

If you tell me your database structure, I could probably knock you up an RSS feed smile.gif

Kurisutaru
This RSS feed is the most annoying thing I have ever faced. I delved deeper into the code and got it to 'somewhat' work. But to my annoyance it has in with it a character limit of 500, something that every time I try and remove it returns "Reference to undefined entity 'not'. Error processing resource" If I try and increase 500 to say 700 or even 5000 it does the same. It -has- to stay at 500 for it to work. What is up with this? Also cause of it any error messages get cut off as well, so you can't even see what the error is.

Plus the way this is set up it removes all formatting. While I was able to somewhat fix that by removing the strip_tags from the 'post' section. The issue with the 500 allowed limit breaks stuff up. Plus any formatting, paragraphs and such are gone. It outputs everything in one continuous line. And trying to add in anyhing that would normally fix that, like nl2br it outputs that same error again. It;s like you can't customize or mess with the code at all.

I've always wanted an RSS feed for my site, I've seen some very nice ones from other sites, ones with full text, images, stuff that makes you want to view the site. But this one is ridiculous. In my years experience with php I have never seen code work this way. What is more frustrating, is for whatever reason every time it outputs that error and I change back what I did (or revert back to the old 'semi working' version) it STILL displays the error as if I didn't touch a single thing. I can even verify that it uploaded by viewing file from my FTP, yet it still shows the old error.
Mine is still displaying: <b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/home/m...
And again the 500 limit cuts off the error.

I hope Jem can come up with something much better then this. Anything would be better then this.
loadx
Understanding how the code works is the real question you should be asking.. That way you can fix it for yourself. Look at the structure of an XML file and think how the code is generating it.

1. forces the content-type to be XML

2. Obviously its generating each <item> using the data from the mysql query's current row as well as populating the the other tags using the related fields.

RSS has a strict format, on dates etc so you might want to read up on it, with only a bit of knowledge about MySQL, PHP and RSS you should be able to manipulate the code easy.
Jem
I haven't forgotten that I offered to do this btw, but ended up in a meeting in Cardiff (Wales) yesterday so I was too tired to do anything by the time I got home.
Vixx
QUOTE(Jem @ Jan 23 2007, 04:52 PM) *
I haven't forgotten that I offered to do this btw, but ended up in a meeting in Cardiff (Wales) yesterday so I was too tired to do anything by the time I got home.


Awww - we could have had coffee!!

Nope, I didn't check the tutorial but neither did I approve it, so for once the blame can't be laid at my door. tongue.gif I'll remove it until the author can demonstrate that it works. smile.gif
Jem
QUOTE(Vixx @ Jan 23 2007, 08:49 PM) *

Awww - we could have had coffee!!

If I hadn't have had to rely on my boss for transport I'd have come to find you wink.gif
Kurisutaru
So anyone have any luck?
Vixx
I've removed it until it is addressed. Sorry!
loadx
Maybe i'll re-do this tutorial... if someone is willing to check my grammar etc
Jem
QUOTE(Kurisutaru @ Jan 28 2007, 07:50 AM) *

So anyone have any luck?

Sorry, been getting my laptop sorted out after formatting it .. still got your DB info though.
echolalia
I was looking for something like this a few months ago (before the RSS tutorials were up) and came across this discussion: RSS For blog?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.