SQL -> boucle -> XML [ DmDocument() ]
Posté : 18 avr. 2008, 16:14
Bonjour,
Je cherche à faire un XML avec les données de ma bdd. Je fais une boucle mais ça ne marche pas...
Quelqu'un peut m'aider ?
merci !
Je cherche à faire un XML avec les données de ma bdd. Je fais une boucle mais ça ne marche pas...
Quelqu'un peut m'aider ?
merci !
<?php require_once('../Connections/Prisca.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_Prisca, $Prisca);
$query_Recordset3 = "SELECT * FROM archives";
$Recordset3 = mysql_query($query_Recordset3, $Prisca) or die(mysql_error());
$row_Recordset3 = mysql_fetch_assoc($Recordset3);
$totalRows_Recordset3 = mysql_num_rows($Recordset3);
$docXML=new DomDocument(); // constructeur, création d'un document XML
$var=$docXML->createElement("portfolio"); // création d'un élément
$docXML->appendChild($var); // ajout à la racine du document
$var2=$docXML->createElement("picture"); // création d'un élément
$var->appendChild($var2);
while ($row_Recordset3 = mysql_fetch_assoc($Recordset3)) {
$var2->setAttribute("title",$row_Recordset3['description']);
$var2->setAttribute("thumb",$row_Recordset3['image']);
$var2->setAttribute("image",$row_Recordset3['id']);
} ;
$docXML->save('nom_fichier_3.xml'); // enregistrement du fichier XML
mysql_free_result($Recordset3);
?>