Marc
|
| Posted: 07/22/2002, 12:09 AM |
|
I have a form with one text box I changed the textbox in listbox
and i allowed multiple choice th problem is when did multiple choice
the database doesn't take all choice, only the last why?
could someone rescues me?thanks
Great job Codecharge
|
|
|
 |
George L.
|
| Posted: 07/22/2002, 10:32 AM |
|
he problem is this Marc. (If you are using PHP!)
The multiple values entered will get stored in your POST variables like
val=1
val=2
val=3
val=4 ...etc.
But if you are trying to get the values and do something with em, you wil never be able to get all of them, because the values will overwrite themselves everytime. So essentialy the last value will be displayed everytime.
The solution is to create an array to store the values into your POST or GET.
You should change the name of your SELECT box to val[]. This will take every selection and assign them to an array with their own key => value .
You then need a way to get the array values to do what you need with it like inserting, updating or deleting from the database.
Here is a basic format to get the values and loop through them to do something.
$param_name is the name of the SELECT tag such as name=val[].
you would use this function like: getListValues(val);
function getListValues($param_name){
//Initialize connection class -gpl
$db = new clsDBDD_DEV();
global $HTTP_POST_VARS;
global $HTTP_GET_VARS;
$Where = "";
if (isset($HTTP_GET_VARS[$param_name])){
$array_p = $HTTP_GET_VARS[$param_name];
}
if (isset($HTTP_POST_VARS[$param_name])){
$array_p = $HTTP_POST_VARS[$param_name];
}
//$size_p = count($array_p);
if ($array_p){
//print_r($array_p);//Debug
foreach ($array_p as $value){
// Do something here. Dont forget to use $value.
//Execute baby!
$db->query($sSQLx);
}
}
return;
unset($db);
}
Need a more real example, just email mex909gman@netscape.net
|
|
|
 |
|