Re: Logic problem

From: Date: Tue, 20 Apr 2004 15:56:28 +0000
Subject: Re: Logic problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-184015@lists.php.net to get a copy of this message
Apr 20 at 9:55am, Alex Hogan wrote: > function myselect($array1, $array2){ > $query = "SELECT".foreach($array1 as $flds){ $flds[$i]; }. > "FROM".foreach($array2 as $tbls){ $tbls[$n]; } ... Alex, if you merely wish to place the values of an array into your query, you might also try doing it this way: $query = 'SELECT '. implode(', ', $array1). ' FROM '. implode(', ', $array2). ' ... '; Usually when writing queries, I prefer to use sprintf(): $q = 'SELECT %s FROM %s'; $q = sprintf($q, implode(', ',$array1), implode(', ',$array2)); The more complex the query gets, the easier it is to read using this approach. I'm sure some find that debatable. After all, I'm crazy ;) -- Kelly Hallman

« previous php.general (#184015) next »