foreach loop question
Posted: Thu May 20, 2010 3:30 am
Hey all,
I am fairly new to php and programming in general and I am having problem with this. What I have is a multiple selection box. I also have 2 arrays and I need to compare them to see if they match. If any of the items match I need that item to be selected if it doesn't match I don't want it to be selected. Here is what I have but isn't working. The info is take from a mysql database.
The output I get for that is:
Item1*
Item1
Item2
Item2*
Item3
Item3
Output I want:
Item1*
Item2*
Item3
(stars mean selected)
Thanks in advance
-Korki
I am fairly new to php and programming in general and I am having problem with this. What I have is a multiple selection box. I also have 2 arrays and I need to compare them to see if they match. If any of the items match I need that item to be selected if it doesn't match I don't want it to be selected. Here is what I have but isn't working. The info is take from a mysql database.
Code: Select all
<?php
$sel_projects = explode(',',$user->project);
?>
<label style="font-weight:bold" for="project"><?php echo $this->lang->line('user_register_begin_18')?></label>
<select multiple name="project[]" id="project_sel" onchange="">
<?php
foreach($projects->result() as $project)
{
foreach($sel_projects as $sel_project)
{
if ($sel_project == $project->name){
echo "<option selected='selected' value='$project->name'>$project->name</option>";
}
else
{
echo"'<option value='$project->name'>$project->name</option>";
}
}
}
?>
</select><br /><br />Item1*
Item1
Item2
Item2*
Item3
Item3
Output I want:
Item1*
Item2*
Item3
(stars mean selected)
Thanks in advance
-Korki