phatgreenbuds Posted September 25, 2007 Share Posted September 25, 2007 So I have this little script that works great for creating simple XML files. Tonight I tried for the first time to integrate it with a much larger script. Having not really thought it out prior to thi point I have now seen the error in my ways. Question is how to fix it? Here is my XML script: $empName = "{$final_target["picfile"]}" . "\n"; $xml_dec = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n"; $rootELementStart = "<images> \n"; $rootElementEnd = "</images> \n"; $xml_doc= $xml_dec; $xml_doc .= $rootELementStart; $xml_doc .= "<pics> \n"; $xml_doc .= $empName; $xml_doc .= "</pics> \n"; $xml_doc .= $rootElementEnd; $fp = fopen('../images/pics.xml','w'); $write = fwrite($fp,$xml_doc); and here is the script that triggers it. Its pulling all the image paths from a MySQL database. Problem is it creates the single entry in XML instead of listing each one in the structure. So basically I need to figure out how to loop through the "while" and each time add the respective path to the XML file. <?php require_once("../includes2/dbopen.php"); ?> <?php include("functions2/functions.php"); ?> <html> <head> <title>Memories</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link type="text/css" rel="stylesheet" href="../stylesheets/styles.css" /> </head> <body> <?php $query = "SELECT * FROM images"; $target = mysql_query($query); // uses the query variable defined above. confirm_query($target); // calls to the function file. while ($final_target = mysql_fetch_array($target)) { $submitter = "{$final_target["picsubmit"]}"; $description = "{$final_target["picdesc"]}"; $filename = "{$final_target["picpath"]}"; ?> <img src="<?php echo $final_target["picpath"]; ?>" alt="" /> <?php echo "<br>"; echo "<h4>" . $description . "</h4>"; echo "<br>"; echo "Submitted By: " . $submitter; echo "<h4>" . "<hr>" . "</h4>"; echo "<br>"; } //ends the while ?> </body> </html> <?php include("../includes2/dbclose.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/70572-xml/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.