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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]