Here's your updated code:
Things to keep in mind:
1. Your selection button was in another form, that contained only that button, so yes, nothing would have posted even if you did print_r($_POST); which is a good way to check what's in your POST.
2. You can't compare variable $_item to array $item, you must traverse the array and compare each value or use a function that does it for you, such as in_array(), array_search(), etc.
3. Why so many echos? leave HTML as HTML, and PHP as PHP.
4. Your Welcome:
-
-
<?php
-
-
// to test:
-
$projects = array('Type 1' => array('Phase 1','Phase 2','Phase 3'),'Type 2' => array('Phase 4','Phase 5'));
-
-
-
// Get the posted data, if any, or initialize as null or today's date
-
($type = @$_POST['Type']) or $type = '';
-
($item = @$_POST['Item']) or $item = '';
-
($name = @$_POST['name']) or $name = "all";
-
($firstdate = @$_POST['firstdate']) or $firstdate=date("ymd");
-
($lastdate = @$_POST['lastdate']) or $lastdate = date("ymd");
-
($userchoice = @$_POST['userchoice']) or $userchoice = "no";
-
($hourchoice = @$_POST['hourchoice']) or $hourchoice = "no";
-
($ratechoice = @$_POST['ratechoice']) or $ratechoice = "no";
-
($amountchoice = @$_POST['amountchoice']) or $amountchoice = "no";
-
($commentchoice= @$_POST['commentchoice']) or $commentchoice = "no";
-
$choices=array('no','yes');
-
-
?>
-
-
<form action="" method="post" >
-
<p>User(Type username or all): <input type="text" name="name" value="<?php echo $name?>"/><br/></p>
-
<p>Start of Period (yymmdd): <input type="text" name="firstdate" value="<?php echo $firstdate?>"/><br//></p>
-
<p>End of Period(yymmdd): <input type="text" name="lastdate" value="<?php echo $lastdate?>"/><br/></p>
-
-
<select name="Type" onchange="submit();">
-
<option value="">- All projects -</option>
-
<?php
-
foreach(array_keys($projects) as $_type) {
-
// Check if this type was selected last submit
-
$selected = ($type == $_type ? 'selected="selected"' : '');
-
// Print this type as an option
-
echo "<option value='$_type' $selected>$_type</option>";
-
}
-
?>
-
</select>
-
-
<select name="Item[]" multiple="multiple">
-
<option value="">- All phases -</option>
-
<?php
-
if($type) {
-
foreach($projects[$type] as $_item) {
-
// Check if this item was selected last submit
-
$selected = (in_array($_item,$item) ? 'selected="selected"' : '');
-
-
// Print this item as an option
-
echo "<option value='$_item' $selected>$_item</option>";
-
}
-
}
-
?>
-
</select>
-
<br/><br/>
-
-
Display Users
-
<select name="userchoice" onchange="submit();">
-
<?php
-
foreach($choices as $key=>$_selection) {
-
// Check if this type was selected last submit
-
$selected = ($userchoice == $_selection ? 'selected="selected"' : '');
-
-
// Print this type as an option
-
echo "<option value='$_selection' $selected>$_selection</option>";
-
}
-
?>
-
</select>
-
<br>
-
<br>
-
-
Display Hours
-
<select name="hourchoice" onchange="submit();">
-
<?php
-
foreach($choices as $key=>$_selection) {
-
// Check if this type was selected last submit
-
$selected = ($hourchoice == $_selection ? 'selected="selected"' : '');
-
-
// Print this type as an option
-
echo "<option value='$_selection' $selected>$_selection</option>";
-
}
-
?>
-
</select>
-
<br>
-
<br>
-
<p><input type="submit" value="Selections"/></p>
-
-
</form>
-
-
-
Dan