Re: Q: while loop on an array

From: Date: Wed, 23 Jan 2002 16:57:57 +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-81713@lists.php.net to get a copy of this message
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 */

« previous php.general (#81713) next »