Page 1 of 1

rss feed from mysql help

Posted: Thu Nov 04, 2010 7:44 pm
by vegas22
hello

does anyone know why this isnt showing a feed with any data?

im new to rss and am stuggling!

if someone could correct the code for me id thank them a thousand times!!

Code: Select all

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

<rss version="2.0">
<channel>
<title>Name of your site</title>
<description>A description of your site</description>
<link>http://your_home_page_url/</link>
<copyright>Your copyright information</copyright>

<?
$hostname='****'; //// specify host, i.e. 'localhost'
$user='****'; //// specify username
$pass='****'; //// specify password
$dbase='*****'; //// specify database name
$connection = mysql_connect("$hostname" , "$user" , "$pass") 
or die ("Can't connect to MySQL");
$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");

$q="SELECT id,jobname,description,postdate FROM jobmodule LIMIT 0,15 ORDER BY postdate DESC";
$doGet=mysql_query($q);

while($result = mysql_fetch_array($doGet)){
?>
     <item>
        <title> <?=htmlentities(strip_tags($result['jobname'])); ?></title>
        <description> <?=htmlentities(strip_tags($result['description'],'ENT_QUOTES'));?></description>
        <link>http://yoururl.com/pathtostory/and_page.php?p=<?=$result['id'];?></link>
        <pubDate> <?=strftime( "%a, %d %b %Y %T %Z" , $result['postdate']); ?></pubDate>
     </item>  
<? } ?>  

</channel>
</rss>
any help or guidance would be apreciated.

Re: rss feed from mysql help

Posted: Thu Nov 04, 2010 7:55 pm
by Jonah Bron
View the source and post it here (use [syntax=xml][/syntax ] tags).

Re: rss feed from mysql help

Posted: Thu Nov 04, 2010 8:04 pm
by vegas22
Sorry I'm a bit confused. At the moment all i have is the above file and the htaccess file

Re: rss feed from mysql help

Posted: Thu Nov 04, 2010 8:21 pm
by vegas22
Sorry just understood what you ment. I'm on my phone at moment so I can't view the source but the URL is *****

Re: rss feed from mysql help

Posted: Thu Nov 04, 2010 8:35 pm
by Jonah Bron

Code: Select all

<rss version="2.0">
    <channel>
        <title>Your RSS Feed Name or Website Name</title>
        <description>A description of your feed or site.</description>
        <link>http://www.yoursite.com/</link>
        <copyright>Your copyright details</copyright>
    </channel>
</rss>
Well, it doesn't show the "Can't connect to MySQL" or "Can't select database" errors. In the words of Harry Hoo...
Harry Hoo wrote:Two possibilities, Mr. Smart.
One, the query is failing. Place another or die(); at the mysql_query() call.

Code: Select all

$doGet=mysql_query($q) or die('Query failed: ' . mysql_error());
Two, query has no results.

Re: rss feed from mysql help

Posted: Thu Nov 04, 2010 8:46 pm
by vegas22
ok got it working had an error and needed to remove
ORDER BY postdate DESC

now its working but i have another issue

the layout doesnt work in IE, firefox picks it up of and does a correct layout, any ideas?

thanks again for your help

Re: rss feed from mysql help

Posted: Thu Nov 04, 2010 9:07 pm
by Jonah Bron
What do you mean the layout? It doesn't detect it as an RSS feed? If so, could be because you're missing the ...

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
... at the beginning.