Jump to content

grmihel

Members
  • Posts

    2
  • Joined

  • Last visited

grmihel's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Thanks for your input. I didn't think about how to loop through each apartment for each customer.The problem with the joint is excatly as you wrote, that you have to make some code that track if it is a new customer or a apartment that should append to the current customer.For now I have created the solution where I:1. Looping through each Customer with a while for row fetching.2. For each Customer I'm looping through, I'm creating a new loop, with a SELECT DISTINCT for each Apartment, where the Apartment's FK is equal with the Customer's PK. There is a bit more coding than I'm used to with C#, but when using the following structure:while($row1 = sqlsrv_fetch_array($result_AllCustomers, SQLSRV_FETCH_ASSOC)){ //Set CustID $custID = $row1['CustID']; //Create customernode $node = $root->appendChild( $dom->createElement("customer")); //Create Customername as attribute to customer node $node->appendChild( $dom->createAttribute("customerName"))->appendChild( $dom->createTextNode(utf8_encode($row1['CustName'])));etc... 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?
  2. 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.
×
×
  • Create New...