RE: [PHP] NEED HELP: select box repeat
| From: | Luboslav Gabal ml. | Date: | Mon, 17 Sep 2001 21:55:16 +0000 |
| Subject: | RE: [PHP] NEED HELP: select box repeat | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-67648@lists.php.net to get a copy of this message | ||
> OK I am trying to write a script that will bring data out of a database
into
> a select box. But what I need it to do is repeat 5 times or more depending
> on what it brings out. I can only get it to display one select box. Here
is
> what I got so far:
>
> <?php
> require 'common.inc';
> // Connect to the Database
> if (!($link = mysql_pconnect($DB_SERVER, $DB_LOGIN, $DB_PASSWORD))){
> DisplayErrMsg(sprintf("internal error %d:%s\n",
> mysql_errno(), mysql_error()));
> exit() ;
> }
> ?>
>
> <head>
> <title>Flavors Select</title>
> </head>
>
> <body>
> <?php
> // Send the Query to the Server, to get the list of flavors
> if (!($result = mysql_db_query($DB,"SELECT * FROM extras WHERE
name='$flav'
> ORDER BY 'choice'")))
> {
> DisplayErrMsg(sprintf("internal error %d:%s\n",
> mysql_errno(), mysql_error()));
> return 0 ;
> }
> ?>
> <font face="verdana" size="2" color="#000000">
> <form name="thisform" action="<?php $PHPSELF;?>"
> method="post">
> <select>
> <option><?php echo $flav; ?>
> <?php while(($row = mysql_fetch_array($result)))
> {
> ?>
> <option value="<?php echo $row["choice"]; ?>"><?php echo
> $row["choice"];
?>
> <?php
> } // End of while loop
> ?>
> </select>
> </form>
> </font>
> </body>
>
> <?php
> }
> ?>
Try to check if query doesn't return only one row, for example:
echo mysql_num_rows($result);
Luboslav Gabal