Jump to content

XML?


phatgreenbuds

Recommended Posts

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"); ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.