Multiple value selection box (mix php/html problem) returning only one value
| From: | Michael Kelley | Date: | Tue, 22 May 2001 14:20:28 +0000 |
| Subject: | Multiple value selection box (mix php/html problem) returning only one value | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-7827@lists.php.net to get a copy of this message | ||
Situation:
I'm using a DB query to bring back a list of values to populate a selection box on a form. I would like the user to be able to select multiple values.
As it stands my code is only returning the last value selected.
I plan to use the selected values to run more queries so I believe the best way to handle multiple values is to put them in an array and then run queries based on the array. That's the next stage
How should I change this code to have $earnType return multiple values
I'm guessing this is a mix of the html & php But I'm betting someone else has solved this already.
Here's the code
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>OCFR List Page</title></head> <body> <?php include("DB.inc"); if($earnType) { $ET = explode(":",$earnType); while ( list($key, $value) = each($ET)) print ("Key: $key, Value: $value <br>"); } Else { $db = odbc_connect($database, $login, $pwd); $cur = odbc_exec($db, "SELECT Distinct EARNTYPE FROM ISIDBA.ISI_CDB_OBJ_T Order by EARNTYPE"); $fields = odbc_num_fields($cur); $Outer=0; print "<tr>"; print "<form action=\"$PHP_SELF\" method = \"post\">"; print "<center>Please pick an Earn Type </center><br>"; print "<center><select name = \"earnType\" multiple size = \"10\">"; while( odbc_fetch_row( $cur ))
{
$Outer++;
for($i=1; $i <= $fields; $i++)
{
printf("<option value = \"%s\">%s</option>",
odbc_result( $cur, $i ), odbc_result( $cur, $i ));
}
}
print "</table>";
print "</select></center>";
print "<br><center><input type = \"submit\" value = \"Submit\"></center>";
print "</tr>";
odbc_close( $db);
}
?>
</body>
</html>
--
Michael Kelley
mkelley@nmsu.edu
Programmer/Systems Analyst I
New Mexico State University
Information and Communication Technologies
Work # (505)-646-1374
P.O. Box 30001
MSC: 3AT
Las Cruces, NM 88003