RE: [PHP] option tags and WHILE

From: Date: Mon, 20 Aug 2001 05:29:09 +0000
Subject: RE: [PHP] option tags and WHILE
Groups: php.general 
Request: Send a blank email to php-general+get-63453@lists.php.net to get a copy of this message
Also while ($array[1] >= $array[0]) { and not while ($array[1] => $array[0]) { Rudolf Visagie rudolf@qedi.co.za -----Original Message----- From: David Robley [mailto:huntsman@www.nisu.flinders.edu.au] Sent: 20 August 2001 07:01 To: CGI GUY; php-general@lists.php.net Subject: Re: [PHP] option tags and WHILE On Mon, 20 Aug 2001 12:23, CGI GUY wrote: > What's wrong with this code? I keep getting a parse > error at the form/select lines... > > $array = mysql_fetch_array($mysql_result) or die("no > go"); > > print ("<form>"); > print ("<select>"); > while ($array[1] => $array[0]) { > print ("<option value=\"$array[0]\ > ">$array[1]</option>\n"); > } > print ("</select>"); > print ("</form>"); > ?> That's an, er, interesting script. But it's not going ever to do what I think you expect it to. You need to use while to loop through the rows returned by your SQL query, and for each iteration in the while loop, print the values you need. Also, if you use extract, you can directly access variables that have the same names as the rows in your table, so you don't have to refer to array elements. Frinstance, if you are fetching fields named value and label for this exercise, something like: echo '<FORM><SELECT>'; while ($array = mysql_fetch_array($mysql_result)) { extract($array); echo '<OPTION VALUE="' . $value . '">' . $label . '</OPTION>'; } echo '</SELECT></FORM>'; Of course, you'll need to put some more info in your <FORM> tag and add submit buttons and so forth. -- David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA Ensign Expendable, step on that rock! - Kirk -- 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 (#63453) next »