Help with multidimensional array setting up a mysql query..

From: Date: Tue, 15 Aug 2000 14:46:47 +0000
Subject: Help with multidimensional array setting up a mysql query..
Groups: php.general 
Request: Send a blank email to php-general+get-11814@lists.php.net to get a copy of this message
This is causing me quite a headache, and I would appreciate any help. I have to run 14 queries (one for each table in a database -- don't ask why, the clients database design is flawed, and I don't have time to redesign a database of this size).. The queries I have to write to search through each table have to change, because the naming between tables is not consistent. if ($VENDOR == 'all') { // this is not fun.. declare multidimensional array of parts and values to set up a billion // different mysql queries, instead of giving mysql a hernia with one big one which would // be a pain if not impossible to format results for. // the databases really should be redesigned if this wants to be efficient as possible. $bigarray = array("abeparts" => array("ABEPN", "CABEPN", "DESCRIPTION", "QUANTITY", "PRICE"), "gudenparts" => array("GUDENPN", "CGUDENPN", "DESCRIPTION", "PRICE")); while (list ($key1) = each ($bigarray)) { $subquery = "SELECT "; while (list ($key2, $val) = each ($bigarray["$key1"])) { $subquery .= " $val,"; } $subquery .= " from $key1 where "; $part = $bigarray[$key1][0]; $subquery .= " $part like PARTNUM"; echo $subquery; echo '<br>'; } // end while } // end if vendor == all loop The problem is that the statements are printing out like: SELECT ABEPN, CABEPN, DESCRIPTION, QUANTITY, PRICE, from abeparts where ABEPN like PARTNUM SELECT GUDENPN, CGUDENPN, DESCRIPTION, PRICE, from gudenparts where GUDENPN like PARTNUM which is REALLY CLOSE to what I want. The problem is the last array element, (PRICE).. it adds the comma after it, which I understand why it does. I just don't know how to write something to say "Hey, this is the last element in the array, so $subquery .= " $val", not $subquery .= " $val,". I tried to get a count or sizeof the array, and I could loop based on that easily, but for some reason I can't seem to obtain the count/sizeof my multidimensonal arrays correctly. Can anyone help? Thanks, Chad Chad Day Beach Associates When I speak german... I think german in my head... but like...Do skript kiddies see a w40l3 8uncha 1's and 0's and 3's and 4's and 7's in their h34d'5 w43n t43y R +a1k1n6 ? -- SirStanley

« previous php.general (#11814) next »