|
Posted by pbali on 03/08/06 23:51
Hi,
I am using PHP 5.1 and MySQL. I have a result set obtained by executing
PDO:: query. I want to create an XML file by using this result set. The
XML file will contain column names as XML node name and column values
as node values.
$orders = $db->query($sql);
if (!empty($orders)) {
foreach ($orders as $row) {
foreach($row as $key=>$value) {
print $key . " => " . $value . "<br>";
// XML Elements will be created here...
}
}
}
The result of this loop as follows:
orderID => 1
0 => 1
packageSKU => SKU1
1 => SKU1
fullName => John Doe
2 => John Doe
address =>address1
3 =>address1
city => city1
4 => city1
itemTypeLabel => mailer
5 => mailer
When I am iterating through foreach loop, I am getting associative
array names and indices together. For example, after getting orderID as
$key in the first run, I am getting 0 as $key in the second run, etc.
which I don't want to. I just want to use the associative array names.
I appreciate if you can let me know if you have any idea what might be
the reason.
Thanks in advance.
Sincerely,
Pelin Bali.
[Back to original message]
|