Date: 04/03/07 (PHP Community) Keywords: php, mysql, sql I have two tables "Clients" and "ShippingAddresses" that I am trying to join to output two separate form dropdown boxes. Unfortunately I am only now beginning to use the Join command and so I'm running into issues, and could really use some assistance. Below the cut is my old code: $grabClients = mysql_query("SELECT Client_ID, Client_Company FROM Clients ORDER BY Client_Company ASC") or die(mysql_error()); if (mysql_num_rows($grabClients) == 0) { $clientList = ""; $shippingList = ""; } else { $clientList = ""; $shippingList = ""; while ($loopClients = mysql_fetch_array($grabClients)) { $grabShipping = mysql_query("SELECT Address_ID, Address_Company, Client_ID FROM ShippingAddresses WHERE Client_ID = '$loopClients[Client_ID]' ORDER BY Address_ID ASC") or die(mysql_error()); if (mysql_num_rows($grabShipping) == 0) { $clientList .= ""; } else { $clientList .= ""; $shippingList .= ""; } } } This code, which probably makes many of you cry inside, outputs two variables full of form options. Variable 1 $clientList is just a simple list of clients. Variable 2 $shippingList is a bit more complex in that it shows an OPTGROUP with a label of the Client, and then a listing of all secondary shipping addresses associated with that client. My attempts at joining were pretty much failures - in two particular areas. 1.) How do I prevent $clientList from outputting duplicate entries for Client names? I have 2 clients and 2 Addresses - both addresses belong to a single client. So on the $clientList it's outputting that client twice. 2.) How do I loop so that for each Address_ID it outputs a new option value? My attempts result in a very odd PHP error about memory limits being exceeded; so I'm sure my loop format is just... broken.
|