Can someone please help me?

Hi!

I want to make RSS feed from my web page, but I just want to show last 10 items in the feed, without using the SQL databases.

Is it possible?
I mean whether through XML or something else, where only past 10 records will be saved not all.
If so, please tell me the way how to do this?

Just so we’re clear, are you wanting to create an RSS feed of your own websites data or another?

Yes I want to create RSS feed from a web page of mine.

Where do you currently get your data from, is it manually created or is it stored in a database? Do you currently use a CMS? Do you have a link your website which displays the 10 pieces you wish to provide in your feed? Speaking of which, what are these 10 items, articles, news items?

actually, I am working on localhost.
but the 10 items are the headings of the products (for a products website I am trying to make for my college project).

It is not a CMS, it is built in custom, by myself.
And currently the web page data is static.

Are you only ever going to only have 10 products?

Something like get data from my own static web page using get_file_contents or something else??

No in future the products will increase…

I assume you could do something like web scraping with file_get_contents, and find each product through a lot of string manipulation…However things would be simplified A LOT using a database, because you could easily run a query to select the newest 10 items and add them to an rss feed.

Yes, with SQL we could do this easily, but I want something like without database, or only using XML.
So that in future no configuration will be needed.

And only limited items will be stored in that XML (say 20), and after that when new product is inserted, it should act as LIFO (Last In First Out, and so on…)

Is it possible in MySQL or SQLite that, only 20 items will be stored, and after that when I insert, the first element (product) inserted will be popped up (LIFO).

I don’t want to make my database keep more than 20 items, but I want to keep just the recent ones…

This should get you started, once you figure out where your going to store product data you can just replace the $products array.


<?php
#add your products here.
$products = array(
  array(
    'title' => 'Product 1',
    'link'  => 'http://www.example.org/product-1.html',
    'description' => 'Product 1 is cool!'
  ),
  array(
    'title' => 'Product 2',
    'link'  => 'http://www.example.org/product-2.html',
    'description' => 'Product 2 is alright.'
  ),
);

header('Content-Type: application/xml; charset=UTF-8');
?>
<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>Shop Foo</title>
    <link>http://www.example.org/</link>
    <description>Shop Foo RSS</description>
    <?php foreach($products as $product): ?>
      <item>
         <title><?php echo $product['title']; ?></title>
         <link><?php echo $product['link']; ?></link>
         <description><?php echo $product['description']; ?></description>
      </item>
    <?php endforeach; ?>
  </channel>
</rss>

As the rest of the site is static, it seems little pointless to add another place to store the products which you want to be displayed in the RSS feed. You may as well just add them directly.

Thank you sir.
I am trying this…

Sir, 1 error is coming, on this line
<?xml version=“1.0”?>

I also tried this <?xml version=“1.0” encoding=“UTF-8”?>
But again on this line error is coming.

When I remove them, the code is working fine sir.
Is it compulsory to put this line sir?

Your server probably has short tags enabled, try this. :wink:


<?php
#add your products here.
$products = array(
  array(
    'title' => 'Product 1',
    'link'  => 'http://www.example.org/product-1.html',
    'description' => 'Product 1 is cool!'
  ),
  array(
    'title' => 'Product 2',
    'link'  => 'http://www.example.org/product-2.html',
    'description' => 'Product 2 is alright.'
  ),
);

header('Content-Type: application/xml; charset=UTF-8');
echo '<?xml version="1.0"?>';
?>
<rss version="2.0">
  <channel>
    <title>Shop Foo</title>
    <link>http://www.example.org/</link>
    <description>Shop Foo RSS</description>
    <?php foreach($products as $product): ?>
      <item>
         <title><?php echo $product['title']; ?></title>
         <link><?php echo $product['link']; ?></link>
         <description><?php echo $product['description']; ?></description>
      </item>
    <?php endforeach; ?>
  </channel>
</rss>

Thank you sir.
It is working now.
Many many thanks sir.

Sir, if you don’t mind, one little question.
Is it possible to put only certain values as I states earlier like 10 or 20 in the MySQL or SQLite database?

And keep updating the new products and removing the old ones…

Sure, anything is possible. :slight_smile:

Thanks sir, i am searching internet to do this.
however it seems to be complicated.