I am creating XML using a while loop, but now I need to prepend and append the generated XML with the XML header info and wrapper tag, but I am struggling to get it to work, here is my code,
$result = mysql_query("SELECT * FROM users")
or die(mysql_error());
$row = mysql_fetch_array($result);
while ($row = mysql_fetch_array($result)) {
$pumaXML = "<userDetails>";
$pumaXML .= "<userID>".$row['uid']."</userID>";
$pumaXML .= "<userName>".$row['userName']."</userName>";
$pumaXML .= "<points>".$row['points']."</points>";
$pumaXML .= "<imageURL>".$row['imageURL']."</imageURL>";
$pumaXML .= "<thumbURL>".$row['thumbURL']."</thumbURL>";
$pumaXML .= "</userDetails>";
};
I can't seem to find a way to do this, I also tried making a function, but that didn't go that well, here is that code,
function createXML($result) {
while ($row = mysql_fetch_array($result)) {
$pumaXML = "<userDetails>";
$pumaXML .= "<userID>".$row['uid']."</userID>";
$pumaXML .= "<userName>".$row['userName']."</userName>";
$pumaXML .= "<points>".$row['points']."</points>";
$pumaXML .= "<imageURL>".$row['imageURL']."</imageURL>";
$pumaXML .= "<thumbURL>".$row['thumbURL']."</thumbURL>";
$pumaXML .= "</userDetails>";
};
return $pumaXML;
};
Thanx in advance!
See Question&Answers more detail:os