Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

RSS PHP/MySQL not working

Guest
Nov 19, 2009 Nov 19, 2009

I cannot figure out why this rss document is not working!? Thankx for any further help:)

<?php
header("Content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

// set RSS version.
echo "
<rss version=\"2.0\">";
 
  // start the XML
  echo "
  <channel>
    <title>CMD - Visual Interface Design</title>
    <descritpion>Inspiratie</description>
    <link>http://vakgroep.cmd.hro.nl/vid</link>";
   
    // create a connection to your database.
    require("myconnection.php");
   
    // query database and select the last 10 entries.
    $data = mysql_query("SELECT * FROM ul_posts ORDER BY post_id DESC");
    while($row = mysql_fetch_array($data))
    {
    // convert database images data into actual image link
    $row[post_foto01] = str_replace("images/", "http://vakgroep.cmd.hro.nl/vid/fotos/", $row[post_foto01]);
   
    // continue with the 10 items to be included in the <item> section of the XML
    echo "
     <item>
    <link>http://www.vakgroep.cmd.hro.nl/vid/tag.php?id=".$row[post_id]."</link>
    <guid isPermaLink=\"true\">http://www.vakgroep.cmd.hro.nl/vid/tag.php?id=".$row[post_id]."</guid>
    <title>".$row[post_title]."</title>
    <description>".substr($row[post_content1],0,150)."</description>
    </item>";
    }
    echo "
     </channel>
     </rss>";

?>

TOPICS
Server side applications
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 19, 2009 Nov 19, 2009

<?php
header("Content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

// set RSS version.
echo "
<rss version=\"2.0\">";
 
  // start the XML
  echo "
  <channel>
    <title>My Title</title>
    <descritpion>Inspiratie</description>
    <link>http://mysite.nl</link>";
   
    // create a connection to your database.
    require("myconnection.php");
   
    // query database and select the last 10 entries.
    $data = mysql_query("SELECT * FROM ul_posts ORDER BY post_id DESC");
    while($row = mysql_fetch_array($data))
    {
    // convert database images data into actual image link
    $row[post_foto01] = str_replace("images/", "http://mysite.nl/fotos/", $row[post_foto01]);
   
    // continue with the 10 items to be included in the <item> section of the XML
    echo "
     <item>
    <link>http://www.mysite/tag.php?id=".$row[post_id]."</link>

    <guid isPermaLink=\"true\">http://www.mysite.nl/tag.php?id=".$row[post_id]."</guid>

    <title>".$row[post_title]."</title>
    <description>".substr($row[post_content1],0,150)."</description>
    </item>";
    }
    echo "
     </channel>
     </rss>";

?>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 04, 2009 Dec 04, 2009

I am looking for a good tutorial for this RSS feed (PHP/ MySQL) I tried so many but nothing is working..

This last one at least shows that something is happening. But there is no content.

<?PHP

header("Content-type: text/xml");

$host = "localhost";
$user = "user";
$pass = "password";
$database = "db";

$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");

$query = "SELECT * FROM ul_posts ORDER BY post_id DESC LIMIT 5";
$resultID = mysql_query($query, $linkID) or die("Data not found.");

$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output = "<rss version=\"2.0\">\n";
$xml_output .= "<channel>\n";

for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
    $row = mysql_fetch_assoc($resultID);
    $xml_output .= "\t<item>\n";
    $xml_output .= "\t\t\t<title>".$query["post_title"]."</title>\n";
    $xml_output .= "\t\t\t<enclosure url='http://vakgroep.cmd.hro.nl/vid/fotos/".$query['post_foto01']."' />\n";
    $xml_output .= "\t\t\t<link>http://vakgroep.cmd.hro.nl/vid/tag.php?id=".$query['post_id']."</link>\n";
    $xml_output .= "\t\t\t<content>".$query['post_content1']."</content>\n";
    $xml_output .= "\t</item>\n";
}

$xml_output .= "</channel>";
$xml_output .= "</rss>";

echo $xml_output;

?>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 07, 2009 Dec 07, 2009

Ullitasch wrote:

I am looking for a good tutorial for this RSS feed (PHP/ MySQL) I tried so many but nothing is working..

This last one at least shows that something is happening. But there is no content.

It's not surprising. But you'll kick yourself when you realize the simple error in your code. You're using $query to try to display the database results. It should be $row.


for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
    $row = mysql_fetch_assoc($resultID);
    $xml_output .= "\t<item>\n";
    $xml_output .= "\t\t\t<title>".$query["post_title"]."</title>\n";
    $xml_output .= "\t\t\t<enclosure url='http://vakgroep.cmd.hro.nl/vid/fotos/".$query['post_foto01']."' />\n";
    $xml_output .= "\t\t\t<link>http://vakgroep.cmd.hro.nl/vid/tag.php?id=".$query['post_id']."</l ink>\n";
    $xml_output .= "\t\t\t<content>".$query['post_content1']."</content>\n";
    $xml_output .= "\t</item>\n";
}

$xml_output .= "</channel>";
$xml_output .= "</rss>";

echo $xml_output;

?>

$query["post_title"] should be $row["post_title"] and so on.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 08, 2009 Dec 08, 2009
LATEST

Hello,

Since long time ago i made this tutorial

:: How to Create a Dynamic RSS Feeds ::
Hello everyone... RSS feeds are very useful within sites, as they allow integrating for you website...

Please check it and it may help

__
Best Regards
Waleed Barakat
Developer-Online Creator and programmer

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines