Page 1 of 1

Problem with array loop

Posted: Tue Jul 10, 2007 8:37 am
by nmpku
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am trying to write a script that outputs my MySQl db info into xml format.  I have this script so it is echoing the name and the field value, however, it is only doing this for the first array...that is it. This script is driving me up the wall. Can a fresh pair of eyes look at it and tell me why the output is only for the first field name and value. Thanks.

Here is the Code Snippet
*****************************

Code: Select all

[// output basic header info and beginning of xml tags
$output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$output .= "<Asset>";
$output .= "<AssetType>";
$output .= "File";

// output basic header info and beginning of xml tags
$result_fld = mysql_query( "Select * FROM file ORDER BY fileid", $dbhandle );
$result_show = mysql_query( "SHOW FIELDS FROM file", $dbhandle );


//count the number of records in the table
$story_total_rows = mysql_num_rows($result_fld);

//build the loop to pull in values for each field
for( $x=0; $x < $story_total_rows; $x++) {
while( $row = mysql_fetch_row($result_fld) ) {
$i=0;
while( $row1 = mysql_fetch_array($result_show) ) {
$output .= "<Field>";
$output .= "<Name>" .$row1[0];
$output .= "</Name>";
$output .= "<Values>";
$output .= "<Value>" .$row[$i] ."</Value>";
$output .= "</Values>";
$output .= "</Field>";
$i++;
}
}
}

$output .= "</AssetType>";
$output .= "</Asset>";

// tell the browser what kind of file is come in
header("Content-type: text/xml");
// print out XML that describes the schema
echo $output;

// close the connection
mysql_close($dbhandle);
?>
]
*****************************
End of Code


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Jul 11, 2007 8:42 am
by nmpku
Sorry, just copied from my post on another site , and posted here...anyway, I found a solution, thanks