I am trying to create a XML document from information extracted from a mysql table. I am using a tutorial to accomplish this
http://www.tonymarston.net/php-mysql/dom.html#a5
what I want to do is to create each element separately, instead of creating them all at once as shown in the tutorial. In order to do that I am trying to place the specific field name into the foreach loop below, any help would be greatly appreciated.
foreach ($row as where fieldname should go 开发者_C百科 => $row['artistname'])
{
$artval = $doc->createTextNode($row['artistname']);
$artval = $chil->appendChild($val);
}
mysql_fetch_assoc
will fetch the data of a whole row, and return an array, indexed by fields names.
Which means that, after using this line :
$row = mysql_fetch_assoc($resouter);
The $row
variable will be an array containing several items ; one for each column returned by the SQL query.
To see that, you can use something like :
var_dump($row);
Which will dump to the standard output the content of the $row
variable -- which could help you figure out what it contains.
Then, if you just want to access one field of this array, no need fdor a loop : $row
being an associative array, you can use syntax such as $row['NAME OF THE FIELD']
to access each field.
精彩评论