Home > Archive > PHP Language > August 2006 > Display of multiple selection box
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Display of multiple selection box
|
|
| rukkie 2006-08-08, 7:57 am |
| I encountered a problem for which I cannot find a solution ...The
situation is as follows : there is a webform in which there are
multiple selection boxes. If people check more than 1 option in the
multiple selection box, the various options are stored in 1 domain in a
mysql db, seperated by a slash ('/'). The problem I have now is when a
display is asked of the webform, I can not get the multiple options
highlighted in the multiple selection box. In the PHP part I'm able to
get the various options selected, via stringhandling, seperated and
stored in an array $act[i], but then in the <HTML> part I am stuck with
the highlighting of the selected items. I've tried already a lot of
combinations and I think it is just a matter of some <, > or { or }
which are not at the correct place, but I can't figure it out anymore.
Here is the code which is part of the <HTML> part of a PHP page :
<select multiple="multiple" size="3" name="activitylist[]">
<?php for ($i=1; $i<=$maxact; $i++) { ?>
<option value="In House Installation and Commissioning" <?php
if ($act[$i]== 'In House Installation and Commissioning') echo
'selected';?>>In House Installation and Commissioning</option>
<option value="On Site Installation\Upgrade" <?php if
($act[$i]== 'On Site Installation\Upgrade') echo 'selected';?>>On Site
Installation\Upgrade</option>
<option value="On Site Support" <?php if ($act[$i]== 'On Site
Support') echo
'selected';?>>On Site Support</option>
<option value="On the Job Training (on site)" <?php if
($act[$i]== 'On the Job Training (on site)') echo 'selected';?>>On the
Job Training (on site)</option>
<option value="Remote Installation\Upgrade" <?php if
($act[$i]== 'Remote Installation\Upgrade') echo 'selected';?>>Remote
Installation\Upgrade</option>
<option value="Remote Support" <?php if ($act[$i]== 'Remote
Support') echo
'selected';?>>Remote Support</option>
<?php }?>
I get an emtpy selection box, with no text an with, ofcourse, nothing
highlighted. Is there anybody out here who experience with this kind of
stuff ?
Thanks in advance ...
| |
| Dennis de Wit 2006-08-08, 7:57 am |
| rukkie wrote:
> I encountered a problem for which I cannot find a solution ...The
> situation is as follows : there is a webform in which there are
> multiple selection boxes. If people check more than 1 option in the
> multiple selection box, the various options are stored in 1 domain in a
> mysql db, seperated by a slash ('/'). The problem I have now is when a
> display is asked of the webform, I can not get the multiple options
> highlighted in the multiple selection box. In the PHP part I'm able to
> get the various options selected, via stringhandling, seperated and
> stored in an array $act[i], but then in the <HTML> part I am stuck with
> the highlighting of the selected items. I've tried already a lot of
> combinations and I think it is just a matter of some <, > or { or }
> which are not at the correct place, but I can't figure it out anymore.
> Here is the code which is part of the <HTML> part of a PHP page :
>
> <select multiple="multiple" size="3" name="activitylist[]">
> <?php for ($i=1; $i<=$maxact; $i++) { ?>
> <option value="In House Installation and Commissioning" <?php
> if ($act[$i]== 'In House Installation and Commissioning') echo
> 'selected';?>>In House Installation and Commissioning</option>
> <option value="On Site Installation\Upgrade" <?php if
> ($act[$i]== 'On Site Installation\Upgrade') echo 'selected';?>>On Site
> Installation\Upgrade</option>
> <option value="On Site Support" <?php if ($act[$i]== 'On Site
> Support') echo
> 'selected';?>>On Site Support</option>
> <option value="On the Job Training (on site)" <?php if
> ($act[$i]== 'On the Job Training (on site)') echo 'selected';?>>On the
> Job Training (on site)</option>
> <option value="Remote Installation\Upgrade" <?php if
> ($act[$i]== 'Remote Installation\Upgrade') echo 'selected';?>>Remote
> Installation\Upgrade</option>
> <option value="Remote Support" <?php if ($act[$i]== 'Remote
> Support') echo
> 'selected';?>>Remote Support</option>
> <?php }?>
>
> I get an emtpy selection box, with no text an with, ofcourse, nothing
> highlighted. Is there anybody out here who experience with this kind of
> stuff ?
>
> Thanks in advance ...
>
hi,
I'm not really sure what you're trying to do here. You want these 6
items to be shown and repeated for $maxact times?
Please give us some more information. The lists are empty you say.
Perhaps $maxact<1 ?
Josse
| |
| rukkie 2006-08-08, 7:57 am |
| Maybe the problem description was not that clear .... What I want is
when the webform is redisplayed with the data found in the mysql
database, that for a multiple selection box all items are highlighted
which were originally selected by the user. So the result should be the
selection box with the items, selected by the user as found in the
mysql dababase, highlighted.
I was wondering : if in the <?php part, before the <HTML> part of the
PHP page, I use some variables and give these variables some values,
are these variables and values known in the <HTML> part ? Or should you
declare these variables somewhere as global ?
| |
| rukkie 2006-08-08, 6:57 pm |
|
Changing the $maxact variable with a fixed number, give me some (good)
result.
The items originally selected by the user are highlighted, but as
already seen by Josse, the options in the multiple selection box are
repeated a number of times (the fixed number by which I replaced the
$maxact.
How can one prevent that all possibilities are repeated x times, and
that the selections made are highlighted ?
| |
|
| On 8 Aug 2006 06:21:28 -0700, "rukkie" <rukkie@belgacom.net> wrote:
>I encountered a problem for which I cannot find a solution ...The
>situation is as follows : there is a webform in which there are
>multiple selection boxes. If people check more than 1 option in the
>multiple selection box, the various options are stored in 1 domain in a
>mysql db, seperated by a slash ('/'). The problem I have now is when a
>display is asked of the webform, I can not get the multiple options
>highlighted in the multiple selection box. In the PHP part I'm able to
>get the various options selected, via stringhandling, seperated and
>stored in an array $act[i], but then in the <HTML> part I am stuck with
>the highlighting of the selected items. I've tried already a lot of
>combinations and I think it is just a matter of some <, > or { or }
>which are not at the correct place, but I can't figure it out anymore.
>Here is the code which is part of the <HTML> part of a PHP page :
>
> <select multiple="multiple" size="3" name="activitylist[]">
> <?php for ($i=1; $i<=$maxact; $i++) { ?>
> <option value="In House Installation and Commissioning" <?php
>if ($act[$i]== 'In House Installation and Commissioning') echo
>'selected';?>>In House Installation and Commissioning</option>
> <option value="On Site Installation\Upgrade" <?php if
>($act[$i]== 'On Site Installation\Upgrade') echo 'selected';?>>On Site
>Installation\Upgrade</option>
> <option value="On Site Support" <?php if ($act[$i]== 'On Site
>Support') echo
>'selected';?>>On Site Support</option>
> <option value="On the Job Training (on site)" <?php if
>($act[$i]== 'On the Job Training (on site)') echo 'selected';?>>On the
>Job Training (on site)</option>
> <option value="Remote Installation\Upgrade" <?php if
>($act[$i]== 'Remote Installation\Upgrade') echo 'selected';?>>Remote
>Installation\Upgrade</option>
> <option value="Remote Support" <?php if ($act[$i]== 'Remote
>Support') echo
>'selected';?>>Remote Support</option>
> <?php }?>
>
>I get an emtpy selection box, with no text an with, ofcourse, nothing
>highlighted. Is there anybody out here who experience with this kind of
>stuff ?
>
>Thanks in advance ...
your code is hard to read but first thing i would do is simplify the multiselect form like this
<select multiple="multiple" size="3" name="activitylist[]">
<option value="1">In House Installation and Commissioning</option>
<option value="2">On Site Installation\Upgrade</option>
<option value="3">On Site Support</option>
<option value="4">On the Job Training (on site)</option>
ok this is 2 part process..
first part is saving the form data - obviously this will be in a form and you submit the form
process the multiselect items like this.
$activitylist = $_POST['activitylist'];
if($activitylist)
$activitylistString = implode("~", $activitylist);
then you would save the string in your query
that takes care of saving data, now you need to extract and show the seelcted data when you look at
the form, this is how i do it...
you run a select query to get the data and collect the form string
$qry = ....
$activitylistString = $qry['activitylistString'];
then you modify the form like this
<select multiple="multiple" size="3" name="activitylist[]">
<option value="1" <?if (strstr($activitylistString, '1' )) echo "selected" ;?> >In House
Installation and Commissioning</option>
<option value="2" <?if (strstr($activitylistString, '2' )) echo "selected" ;?>>On Site
Installation\Upgrade</option>
<option value="3" <?if (strstr($activitylistString, '3' )) echo "selected" ;?>>On Site
Support</option>
<option value="4" <?if (strstr($activitylistString, '4' )) echo "selected" ;?>>On the Job Training
(on site)</option>
if you expect to have more then 10 items you could use letters instead or have 01, 02 ... becuase
if you do a string match of 1 is could match 1 or 10 or 13 ect...
| |
| Shelly 2006-08-08, 6:57 pm |
|
"rukkie" <rukkie@belgacom.net> wrote in message
news:1155044727.229231.201720@p79g2000cwp.googlegroups.com...
> Maybe the problem description was not that clear .... What I want is
> when the webform is redisplayed with the data found in the mysql
> database, that for a multiple selection box all items are highlighted
> which were originally selected by the user. So the result should be the
> selection box with the items, selected by the user as found in the
> mysql dababase, highlighted.
>
> I was wondering : if in the <?php part, before the <HTML> part of the
> PHP page, I use some variables and give these variables some values,
> are these variables and values known in the <HTML> part ? Or should you
> declare these variables somewhere as global ?
>
In the <html> part you can check with something like
<?php if ($variable[$i] == some_value) echo " checked"; else echo " "; ?>
Where the $variable[$i] has been found in the php part and you are looping
in the <html> part. Remember that you can come in and out of <?php ?> so
you can start your loop and close the php; put in html stuff; in there put
in the above in the option statement; then more html; then close the loop in
another php bracket.
I did this very successfully before.
Shelly
|
|
|
|
|