sto creando un feed rss per un sito, e non essendo molto pratico ho difficolta con le query,
fin ora ho fatto cosi:
Codice PHP:
$host = "localhost";
$user = "nomedatabase";
$password = "password";
$myconn=mysql_connect($host,$user,$password) or die("Errore di connessione");
$db_name="nomedatabase";
mysql_select_db($db_name,$myconn);
$result = mysql_query("SELECT `link_content` , `link_title` , `link_url` FROM `news_links` LIMIT 1, 100")
or die(mysql_error());
function xmlentities ( $string ) {
$ar1 = array ( '&' , '"', ''' , '<' , '>' );
$ar2 = array ( '&', '"', "’", '<', '>' ) ;
return str_replace ( $ar1 , $ar2, $string );
}
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<item><title>";
echo xmlentities($row['link_title']);
echo "</title><link>";
echo htmlentities($row['link_url']);
echo "</link><description><![CDATA[";
echo xmlentities( $row['link_content'] );
echo "]]></description></item>";
}
e tutto funziona come dovrebbe ovvero ho estratto il titolo della news, la descrizione e il link della fonte, ora non riesco a estrarre le categorie perchè nel database sono archiviate come numeri, ovvero se aggiungo link_category alla query sopra ottengo i gli ID delle categorie e non i nomi
i nomi sono contenuti in un altra tabella che si chiama news_categories dove ci sono dentro i campi category_id e category_name che non so come associare per far venire fuori il nome della categoria..