miercuri, 8 decembrie 2010

Cel mai simplu RSS builder in PHP cu MySql

Am sa continui seria de articole mai tehnice, cu o solutie legata de o metoda rapida de constructie RSS. Se da o tabela in MySql si se doreste o soluti rapida de expunere a unui RSS feed.

Solutia?

function getHeader($titlu, $link, $descriere)
{
header (‘Content-type: text/xml’);
echo ‘


’. $titlu .’
’. $link .’
’. $descriere .’
Php’;
}

function getFooter()
{
echo ‘

’;
}

//include baza de date

require_once($_SERVER['DOCUMENT_ROOT'] . “/include/config.inc.php”);
$db=mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbdatabase);

$feed_action = $_GET['modul'];
if ($feed_action == ‘stiri’)
{
getStiri(“Ultimle stiri”, “http://www.stiri.ro/”, “Ultimele stiride de pe stiri.ro”);
}

//add the footer

getFooter();

//get RSS for stiri
function getStiri$titlu, $link, $descriere)
{
getHeader($titlu, $link, $descriere);

//genereaza elementele
$map_result = mysql_query(“SELECT id, stire, data_adaugare FROM stiri WHERE aprobat = 1 order by id desc limit 0,10?);
while ($map_row = mysql_fetch_array($map_result)) {
echo ‘

Stirea  cu numarul ‘. $map_row['id']  .’

http://www.stire.ro/detalii/id/’. $map_row['id'] .’/
’. $map_row['data_adaugare'] .’
’;
}
}

?>


View the original article here

Niciun comentariu:

Trimiteți un comentariu