SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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?

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Just so we're clear, are you wanting to create an RSS feed of your own websites data or another?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I want to create RSS feed from a web page of mine.

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    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?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Are you only ever going to only have 10 products?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  7. #7
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like get data from my own static web page using get_file_contents or something else??

  8. #8
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No in future the products will increase..

  9. #9
    SitePoint Zealot Zurev's Avatar
    Join Date
    Feb 2009
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  10. #10
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...)

  11. #11
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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..

  12. #12
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    This should get you started, once you figure out where your going to store product data you can just replace the $products array.
    PHP Code:
    <?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.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  13. #13
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you sir.
    I am trying this...

  14. #14
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  15. #15
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Your server probably has short tags enabled, try this.

    PHP Code:
    <?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>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  16. #16
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you sir.
    It is working now.
    Many many thanks sir.

  17. #17
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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..

  18. #18
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Sure, anything is possible.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  19. #19
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks sir, i am searching internet to do this.
    however it seems to be complicated.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •