tbl_A
[id | facility_section | assigned_no]
----------
tbl_B
[col1 | col2| issued_to | col3 | col_etc]
----------
The drop down list will retrieve values of facility_section
column of tbl_A
table. Then, the drop down list values will be inserted into issued_to
column of tbl_B
. Code sample:-
<?php
include ('dbconnect.php');
@$i=$_POST['issued_to'];
if(@$_POST['submit'])
{
$s="INSERT INTO tbl_B (issued_to) VALUES ('$i')";
mysql_query($s);
}
@$facility_section = $_POST['facility_section'];
$result = mysql_query("SELECT facility_section FROM tbl_A");
?>
<select name="issued_to">
<option selected disabled>-- Please Select --</option>
<?php
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['facility_section'] . "'>" . $row['facility_section'] . "</option>";
}
?>
</select>
What I want is that, each time the drop down list values is inserted into issued_to
column of tbl_B
, assigned_no
column of tbl_A
will be updated and increased by 1 where it will be increased accordingly:- facility_section
=issued_to
.
I know the code to update:-
UPDATE tbl_A
SET assigned_no = assigned_no + 1
WHERE facility_section = '$facility_section'
But, I'm stuck on how to do this...