I d like some guidance on how how to pass a string variable as part of an xml name.
I m running a mysql query according to the users form selection.Then i create an xml for the result.I d like to pass a variable as the name of the xml.How is this possible?
thats my working code:
$query = "SELECT * FROM $table WHERE diam = '$d' AND nom = '$n' AND dim = '$di' AND type = '$t'";
$query_result=mysql_query($query);
$num_rows = mysql_num_rows($query_result);
if($num_rows == 0) {
echo "bummer!";
} else {
#Creates a new DOMDocument
$doc = new DOMDocument("1.0", "utf-8");
#formats correctly the xml document
$doc->formatOutput = true;
#Create Parent Node
$parent_node = $doc->createElement('marker');
$parent_node = $doc->appendChild($parent_node);
#Row manip
while($row = mysql_fetch_assoc($query_result)) {
#adds node for each row
$row_node = $doc->createElement($table);
#appends the new node to the root
$occ = $parent_node->appendChild($row_node);
#add a child node for each field
foreach($row as $fieldname => $fieldvalue) {
$child = $doc->createElement($fieldname);
$child = $occ->appendChild($child);
$value = $doc->createTextNode($fieldvalue);
$value = $child->appendChild($value);
}
}
#saves generated domDocument into a file.
#If echo'ed outputs filezise in bytes
$xml_string = $doc->save('xmlOutput.xml');
}
instead of the hardcoded “xmlOutput” i d like to display ,lets say the diam column name.
Inside your loop where you loop through the result:
you can access the value of the
diamcolumn by doing:I noticed now that you might be asking for: