Hi I'm new to php and have spent the last 3 days scouring the internet for solutions to my problem!
I have two drop down lists within a table and when I select a value from the second drop down list and submit it, the value I selected in my first drop down list goes back to 0 🙁
I'm sure this is a noobish problem but I would love to know how to work out.
this is my code:
<html>
<head>
<?php
//sums arrays
$band1 = array();
$band1[1]="13903";
$band1[2]="14614";
$band1[3]="14258";
$band1[4]="17537.96";
$band1[5]="70151.82";
$band1[6]="311.79";
$band1[7]="41.57";
$band1[8]="0.69";
$band1[9]="0.0115";
?>
</head>
<body>
<table border="1">
<tr>
<td>Band 1</td>
<td>Number of Staff</td>
<td>Average cost per hour/min/sec</td>
<td> Select hours/mins/sec Drop down menu</td>
<td>Average cost by time per person</td>
</tr>
<tr>
<td>Cost per Hour</td>
<td><FORM NAME ="staff" id="staff_filter" METHOD ="POST" ACTION ="cost improvement tool.php">
<select name="staff1" id="staff1" onchange="document.getElementById('staff_filter').submit();">
<?php
$dopvalue=0;
for ($i=0; $i<201; $i++)
{
?>
<option value="<?php echo $i; ?>"<?php if($i==$_POST["staff1"]) echo "selected" ; ?>><?php echo $i; ?></option>
<?php
}
$dop=$_POST['staff1'];
?>
</select>
</form>
</td>
<td><?php $costphour=$band1[2]*$band1[3];
echo "£" . number_format($costphour); ?></td>
<td><FORM NAME ="report" id="report_filter" METHOD ="POST" ACTION ="cost improvement tool.php">
<select name="cars" id="cars"onchange="document.getElementById('report_filter').submit();">
<?php
//drop down list loop and retaining value
$dropvalue=0;
for ($start=0; $start<201; $start++)
{
?>
<option value="<?php echo $start; ?>" <?php if($start==$_POST["cars"]) echo "selected"; ?>><?php echo $start; ?></option>
<?php
}
$drop=$_POST['cars'];
?>
</select>
</form>
</td>
<td><?php echo $drop;?>
</td>
</tr>
<td>
</table>
</body>
</html>