Re: Q: while loop on an array

From: Date: Wed, 23 Jan 2002 17:01:52 +0000
Subject: Re: Q: while loop on an array
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-81714@lists.php.net to get a copy of this message
isn't speed always an issue? thanks, i really like that idea. i'll do just that and chop off the trailing " || " thanks, joe Jason Wong(php-general@gremlins.com.hk)@Thu, Jan 24, 2002 at 12:57:57AM +0800: > On Thursday 24 January 2002 00:46, Joe Rice wrote: > > Thanks to those who pointed me in the right direction. > > i couldn't go with a for loop because my keys aren't > > sequential, so with a while i came up with this. > > > > $sql = "SELECT aID FROM userAnswers WHERE ("; > > $num_conditions = sizeof($new_answers); > > $count = 1; > > reset($new_answers); > > while( list ($new_qID,) = each($new_answers)){ > > $sql .= "qID=\"$new_qID\""; > > if ($count < $num_conditions) $sql .= " || "; > > $count++; > > } > > $sql .= ") AND uID = \"$uID\""; > > If speed is an issue then you could just have your usual while-loop and then > straight after it, chop off the trailing " || ". > > > -- > Jason Wong -> Gremlins Associates -> www.gremlins.com.hk > > /* > Tomorrow's computers some time next month. > -- DEC > */ > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#81714) next »