Jump to content

Tutorial Generare Feed Rss Din Mysql


Recommended Posts

Posted

Mai jos gasiti un tutorial pas cu pas despre cum puteti crea un Feed RSS PHP cu date din MySql.

ic17.jpg

Pentru inceput trebuie sa va conectati la baza de date:

$con = mysql_connect("localhost","user","parola"); 
mysql_select_db("baza de date", $con);
[/code] [b]Pasul 2:[/b] Selectarea informatiilor
[code]// Select the data
$select = mysql_query( "SELECT * FROM your_table_name ORDER BY businessname" )
or die("SELECT Error: ".mysql_error());
Pasul 3: Creati un output
$rssData = '<?xml version="1.0" encoding="UTF-8" ?>'; 
$rssData .= '<rss version="0.91">';
$rssData .= '<channel>';
$rssData .= '<title>Titlu RSS feed</title>';
$rssData .= '<link>http://Adresa-site</link>';
$rssData .= '<description>Descriere</description>';
$rssData .= '<language>en-us</language>';

while ($row = mysql_fetch_array($select)) {

//Incepem tag <item>
$rssData .= "<item>\n";

// Printare titlu "businessname" - intrare rss
$rssData .= "<title>" . $row['businessname'] . "</title>\n";
// Printam descriere
$rssData .= "<description>" . $row['news'] . "</description>\n";

// Inchidem tag <item>
$rssData .= "</item>\n";

}
// Inchidem output si cream fisierul xml
$rssData .= "</channel>";
$rssData .= "</rss>";
Header("Content-Type: application/xml");
echo $rssData;
[/code] !!! Salvati fisierul sub numele de [color="#FF0000"]rss.php[/color] Iata si un exemplu:
[code]<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("filme", $con);


$select = mysql_query( "SELECT * FROM titluri ORDER BY id DESC" )
or die("SELECT Error: ".mysql_error());


$rssData = '<?xml version="1.0" encoding="UTF-8" ?>';
$rssData .= '<rss version="0.91">';
$rssData .= '<channel>';
$rssData .= '<title>Your RSS Feed</title>';
$rssData .= '<link>http://localhost/update/rss1</link>';
$rssData .= '<description>This is a feed of our hints</description>';
$rssData .= '<language>en-us</language>';

while ($row = mysql_fetch_array($select)) {
$rssData .= "<item>\n";
$rssData .= "<title>" . $row['titlu'] . "</title>\n";
$rssData .= "<description>" . $row['titlu'] . "</description>\n";
$rssData .= "</item>\n";

}
$rssData .= "</channel>";
$rssData .= "</rss>";
Header("Content-Type: application/xml");
echo $rssData;
mysql_close($con);
?>
Ultimul pas este crearea RSS tag-ului pentru site-ul dumneavoastra:
<link rel="alternate" type="application/rss+xml" title="RSS" href="http://your_domain/rss.php" />

Te-ai inregistrat? Ne-ar placea sa te prezinti.

Cum pot sustine forumul?
Cumpara de la eMag folosind acest link.
--------------------
oG2BN9d.gifse1WdXd.gifQG6MtmI.gifRHYjDzD.gifG5p1wui.gif

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • 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.