Jump to content

RSS confusion


lukeUrtnoedki

Recommended Posts

ok, then 

Im stuck on one problem,

heres my assignment

Your RSS feed is to display these fields:

  • Product Name
  • Product Line
  • Product Scale
  • Product Vendor
  • Product Description
  • Buy Price formatted in US dollars

    The product name of each feed item, is to be a link to a product page. You may choose the format of the remaining item data.

I have most of it down, but looked at the available tags and made some guesses, is this ok?

 

<?php header('Content-Type: text/xml'); ?>
<?php echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
<rss version='2.0'>
<channel>
<title><![CDATA[Assignment 9 - Newsfeed]]></title>
<link>http://teamluke.net/</link>
<webMaster>lurtnowski@gmail.com</webMaster>
<description><![CDATA[The trials & Tribulations of Luke Urtnowski as I complete this assignment.]]></description>
<language>en-us</language>
<image>
<title>Luke Urtnowski</title>
<url>http://php_class.tea...images/luke.jpg</url>
<link>http://php_class.tea...images/luke.jpg</link>
<description><![CDATA[The trials & Tribulations of Luke Urtnowski as I complete this assignment.]]></description>
</image>
<?php
require_once('db/conn.php');

try {
$stmt = $conn->prepare('SELECT productCode, productName, productLine, productDescription, productVendor, buyPrice FROM `products` WHERE productLine = "Trains" OR productLine = "Vintage Cars" ORDER BY timeStamp ASC LIMIT 10');

$stmt->execute();

if($stmt->rowCount()) {
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                    echo '<item>';
                    echo ' <link>http://php_class.teamluke.net/Assignment_9/product.php?Code='.$row['productCode'].'>';
                    echo ' <title>' . $row['productName'] . '</title>';
                    echo ' </link>';
                    echo ' <category>' . $row['productLine'] . '</category>';
                    echo ' <source>' . $row['productVendor'] . '</source>';
                    echo ' <description><![CDATA[' . $row['productDescription'] . ']]></description>';
                    echo ' <Price>'
// I looked and couldn't figure out if my code in the while loop makes sence.
// Does it to you?

 
.number_format($row['buyPrice'], 2) . '</Price>';
                    echo '</item>';
}
                }
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
?>

</channel>
</rss>
I looked and couldn't figure out if my code in the while loop makes sence.

Does it to you?

When i try to validate it, I get soo many errors though...

https://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fphp_class.teamluke.net%2FAssignment_9%2Frss.php

Edited by requinix
using [code] instead of a rich text paste
Link to comment
Share on other sites

The CDATA stuff isn't needed for the first <title> tag.

 

For the <webMaster> tag, see the example in the RSS 2.0 Specification (https://validator.w3.org/feed/docs/rss2.html).

 

For the second <link> tag (child of <image>), see the note in the RSS 2.0 Specification (https://validator.w3.org/feed/docs/rss2.html#optionalChannelElements).

Link to comment
Share on other sites

ok, made a few changes and this is where im at.

https://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fphp_class.teamluke.net%2FAssignment_9%2Frss.php

Every error occurred 10- times so the problem is everything in the while loop

 while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        echo '<item>';
	echo '  <link>http://php_class.teamluke.net/Assignment_9/product.php?Code='.$row['productCode'].'>';
	echo '  <title>' . $row['productName'] . '</title>';
	echo '  </link>';
	echo '  <category>' . $row['productLine'] . '</category>';
	echo '  <source>' . $row['productVendor'] . '</source>';
	echo '  <description><![CDATA[' . $row['productDescription'] . ']]></description>';
	echo '  <Price>$' .number_format($row['buyPrice'], 2) . '</Price>';
	echo '</item>';
                    }

I sort of guessed on what tags to use (out of the ones I can) and I had no idea how to use a tag to describe the price.

Thanks for your help thus far 

Link to comment
Share on other sites

Most of the errors refer the tags used within the <item> tag. The available children tags (for <item>) are listed in the RSS 2.0 spec here: https://validator.w3.org/feed/docs/rss2.html#hrelementsOfLtitemgt

 

The specification provides examples on how to use the tags. Note that the <title> tag is a child of <item> and not <link>. And there isn't a tag for <Price>, but you could add that information to the <description> tag.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.