I have posted this last week but I received no responses so I am going to try and explain this better.... I have a question that has been haunting me for days now. I have results from a mySQL database that I am exporting to a CSV. These records are sales form an eCommerce store (ZenCart). What happens is that attributes for each part of an order make a new row for each attribute. Like this: | order | attribute | attribute value | +-------+-----------+-------------+ | 101 | name | bob | +-------+-----------+-------------+ | 101 | address | 123 any street | +------+----------+---------------+ I need the results to be in XML or CSV (XML is preferred) that has a structure like this: <order> <number>101</order> <attribute field=name>bob</attribute> <attribute field=address>123 any street</attribute> </order> OR: <order> <number>101</order> <name>bob</name> <address>123 any street</address> </order> or anything similar I have the SQL query done but formatting the output to be how I need is the hard part. Can someone help me or point me in the right direction?