![](http://content.invisioncic.com/r49260/set_resources_1/84c1e40ea0e759e3f1505eb1788ddf3c_pattern.png)
grmihel
-
Posts
2 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by grmihel
-
-
I'm probably too damaged of working with C# and LinQ, so havn't done a real SQL sentance since my work in Java.I have two tables, which are combined with a PK and FK. Table_MyCust with PK CustID and Table_CustApartments which contain CustID as FK.I want to make a XML document with PHP, where there is a node for each MyCust row, and for each MyCust there is a CustApartments for each apartment that have the current CustID as FK. In C# I've do something like the following:
XElement xml = new XElement("customers", from p in DatabaseConnection.Custs orderby p.CustName select new XElement("customer", new XAttribute("customerName", p.CustName), new XElement("Addresses", (from l in p.Aparts.Distinct() orderby l.Street where l.Street != null && !l.Postal.Equals("1010") select new XElement("Address", (string)l.Street); )));
But how does I do in PHP? Does you create a SQL sentance with some kind of a join operation? Or do you create two SQL statments, and check for equals on the PK and FK while running through all the rows? I'm not sure whats the 'correct' way to do in PHP, since I'm fairly new to PHP scripting yet.
Join two tables to create XML
in PHP
Posted · Edited by grmihel
Its still kinda readable and easy to overview in the source. And even more important, it now has the same XML output structure as my original C# code. Is there any pros and cons for the solution I'm using now? I mean, are there any basics do's and don'ts that I'm violated with this loop with a loop, that I should be aware of?