1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| <?php
//Create Database connection
$db = mysql_connect("localhost","blabla","blabla");
if (!$db) {
die('Could not connect to db: ' . mysql_error());
}
//Select the Database
mysql_select_db("jobs",$db);
$result = mysql_query("SELECT
`jobs_offre`.`offre_titre`,
`jobs_offre`.`offre_description`,
`jobs_offre`.`offre_contrat_id`,
`jobs_offre`.`offre_diplome_id`,
FROM
`jobs_societe`
JOIN
`jobs_offre`
ON(`jobs_societe`.`societe_id` = `jobs_offre`.`offre_societe_id`)
WHERE `jobs_offre`.`offre_visible`='1' AND `jobs_offre`.`offre_actif`='1' AND `jobs_offre`.`offre_valide`='1' AND TO_DAYS(NOW()) - TO_DAYS(`jobs_offre`.`offre_dte_cree`) <= '30';", $db);
//Create SimpleXMLElement object
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><annonces/>');
//Add each column value a node of the XML object
while($row = mysql_fetch_assoc($result)) {
$mydata = $xml->addChild('annonce');
$mydata->addChild('Titre',$row['offre_titre']);
$mydata->addChild('Description',$row['offre_description']);
$mydata->addChild('Contrat_id',$row['offre_contrat_id']);
$mydata->addChild('Diplome_id',$row['offre_diplome_id']);
}
mysql_close($db);
//Create the XML file
$fp = fopen("annonces.xml","wb");
//Write the XML nodes
fwrite($fp,$xml->asXML());
//Close the database connection
fclose($fp);
?> |
Partager