phprssrss2

My RSS feed only show few posts


I'm trying to create an auto feed for my CMS using PDO.
Here's my code. It works but only few posts shown. What's wrong with my code.

<?php
include('dbcon.php');
header("Content-Type: application/rss+xml; charset=ISO-8859-1");
//header("Content-Type: application/rss+xml; charset=utf-8"); 
echo '<?xml version="1.0" encoding="UTF-8" ?>';
echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"  xmlns:dc="http://purl.org/dc/elements/1.1/">';
echo '<channel>';
?>
    <title>Authorized Honda Auto Dealer | Serang Cilegon</title>
    <link>https://hondaautoserang.com/</link>
    <atom:link href="https://hondaautoserang.com/feed/" rel="self" type="application/rss+xml"/>
    <description>authorized honda auto dealer: dealer resmi mobil honda serang &amp; honda cilegon. beli mobil di serang terbukti lebih murah. Cek info harga &amp; promo terbaru: 087774040777.</description>
    <language>id-id</language>
    <copyright>Copyright (C) 2017 hondaautoserang.com</copyright>
    <?php
    $sqlFeed = "SELECT * FROM honda_post ORDER BY id DESC";
    $execFeed = $pdo->query($sqlFeed);
    $execFeed->execute();
    $fetchFeed = $execFeed->fetchAll(PDO::FETCH_ASSOC);
    if ($fetchFeed){
        foreach($fetchFeed as $r){
            $id = $r['id'];
            $title = $r['title'];
            $description = $r['description'];
            $publisher = $r['publisher'];
            $article = $r['article'];
            $image = $r['image'];
            $url = $r['url'];
            $date = $r['date'];
            $category = $r['category'];
            //tampilkan
            echo '<item>';
            echo '<title>'.$r['title'].'</title>';
            echo '<description>'.$r['description'].'</description>';
            echo '<category>'.$r['category'].'</category>';
            //echo '<content:encoded><![CDATA['.html_entity_decode($article, ENT_QUOTES, 'utf-8').']]></content:encoded>';
            echo '<link>'.$r['url'].'</link>';
            echo '<pubDate>'.$r['date'].'</pubDate>';
            //echo '<dc:creator>'.$r['publisher'].'</dc:creator>';
            echo '<guid isPermaLink="true">'.$r['url'].'</guid>';
            echo '</item>';
            }
        }
    ?>
<?php

echo '</channel>';
echo '</rss>';
?>

When I change into ORDER BY id ASC, only 10 posts show (There are 21 posts correctly formatted published right now).


Solution

  • When I checked back into my pdo codes, no problem. But it is because of the ampersand in that title which is invalid according to mozilla browsers and google feedburner.

    Solution: All Ampersands must be change into &amp; Then I use this to change all & in the <title>,<description> by using this follows:

    $title = str_replace('&', '&amp;', $r['title']);
    $description = str_replace('&', '&amp;', $r['description']);
    

    and it works as I wish

    Here's the references: Getting a The entity name must immediately follow the '&' in the entity reference error in java, but I dont have any ampersands in my xml file

    Note:
    But, this question is not duplicate since the question is different of the reference :p