PDA

View Full Version : creating dynamic rss feeds? could someone kindly assist me please?


LJackson
06-01-2010, 04:55 PM
Hi All,

i am trying to create an rss feed from my db of records which i thought would of been 'quite' straight forward so i created a new php page and have the following code

<?xml version="1.0"?>
<rss version="2.0">
<channel>

<title>UK Top 40 DVD Chart</title>
<description>The Top 40 UK DVD Chart</description>
<link>http://www.myurl.com</link>

<?php
include_once("dbinfo.php");

$create_feeds = "SELECT * FROM products WHERE prodCategory = 'DVD' AND prodHotPick = '1'";
$query = mysql_query($creat_feeds)or die(mysql_error());
while($row = mysql_fetch_array($query))
{?>

<item>
<chartPos><?php echo $row['prodName']?></chartPos>
<title><?php echo $row['prodCategory']?></title>
<category>www.myurl.com/dvd/<?php echo $row['prodShortName']?></category>
<link>

<?php?>
</link><?php

}?>
</item><?php echo $row['chartPos']?><?php?>

</channel>
</rss>

but it fails and says Parse error: syntax error, unexpected T_STRING on line 1...

im not really sure of what i am doing here and its obviously wrong :( so if someone could help me out i'd appreciate it

thanks
Luke

abduraooft
06-01-2010, 05:25 PM
Read http://php.net/manual/en/ini.core.php about short_open_tag

LJackson
06-01-2010, 05:37 PM
thanks mate, i've now got a rss feed, although i dont seem to be able to display all the data i want

here is my code
<?php echo '<?xml version="1.0"?>';?>
<rss version="2.0">
<channel>

<title>UK Top 40 DVD Chart</title>
<description>The Top 40 UK DVD Chart</description>
<link>http://www.myurl.com/dvds.php</link>

<?php
include_once("dbinfo.php");

$create_feeds = "SELECT * FROM products WHERE prodCategory = 'DVD' AND prodHotPick = '1' ORDER BY chartPos ASC";
$query = mysql_query($create_feeds)or die(mysql_error());
while($row = mysql_fetch_array($query))
{?>

<item>
<chartPos><?php echo $row['chartPos']?></chartPos>
<title><?php echo $row['prodName']?></title>
<category><?php echo $row['prodCategory']?></category>
<link>http://www.myurl.com/dvd/<?php echo $row['prodShortName']?></link>
</item>
<?php

}?>

</channel>
</rss>

but all im getting displayed in the feed is the title and a link to its webpage :D

how do i get the prodCategory and chartPos to be displayed???

thanks mate..

LJackson
06-01-2010, 07:06 PM
ok i found this page on another thread
http://cyber.law.harvard.edu/rss/rss.html#ltimagegtSubelementOfLtchannelgt

which helps,

but i am still unable to get the images to show

here is my updated code
$create_feeds = "SELECT * FROM products WHERE prodCategory = 'DVD' AND prodHotPick = '1' ORDER BY chartPos ASC";
$query = mysql_query($create_feeds)or die(mysql_error());
while($row = mysql_fetch_array($query))
{?>

<item>
<chartPos><?php echo $row['chartPos']?></chartPos>
<title><?php echo $row['prodName']?></title>
<image>
<url><?php echo $row['prodThumbIMG']?></url>
<title><?php echo $row['prodName']?></title>
<link>http://www.myurl.com/dvd/<?php echo $row['prodShortName']?></link>
</image>
<description><?php echo $row['prodCategory']?></description>
<link>http://www.myurl.com/dvd/<?php echo $row['prodShortName']?></link>
<lastBuildDate></lastBuildDate>
</item>
<?php

}?>


cheers
Luke

abduraooft
06-02-2010, 08:57 AM
<image>
<url><?php echo $row['prodThumbIMG']?></url>
<title><?php echo $row['prodName']?></title>
<link>http://www.myurl.com/dvd/<?php echo $row['prodShortName']?></link>
</image> Are you getting the right values in the source of the page, as the sample code at http://www.w3schools.com/rss/rss_tag_image.asp?

LJackson
06-02-2010, 01:51 PM
i dont think im approaching this the correct way? with the code im trying and in the above link it is seems to suggest that the image tag can only be used for the channel not the individual items?

im sure it can be done as i have seen images in rss feeds, maybe i have to define the element or something first, think i read somewhere that you can create your own elemets but you have to define them? will try and find that again and read through it :D

do you have any ideas?
cheers mate

p.s also im curious to find out how to get the rss icon to appear in the address bar to indicate that the current page can be viewed as an rss. do i need to add some sort of a link similar to when linking css files to a page?

many thanks
Luke

Dormilich
06-02-2010, 02:26 PM
I think that’s the <enclosure> (http://www.rssboard.org/rss-specification#ltenclosuregtSubelementOfLtitemgt) element, you’re looking for.

although you could extend the RSS vocabulary, that doesn’t mean the User Agents (Feed Readers) understand that.

LJackson
06-02-2010, 02:30 PM
Hi mate, thanks for your reply, i have managed to get pictures at last :), i took look at the amazon feeds and they just included the images in the description, and added some styling to place it where they wanted and it works :D

now just need to find out how to set the rss icon in the address bar :)

thanks
Luke

Dormilich
06-02-2010, 02:32 PM
<link rel="alternate" type=… href=…> something like that. press Ctrl + U (Ctrl + Alt + U) to see how it is done here.

LJackson
06-02-2010, 02:48 PM
brill thanks mate, works a treat :D