我有一个带有一些左外部联接表的MySql查询和一个将编辑和更新MySql表的php表 我为属于我正在编辑的表的字段输入了一些文本。我也有一些现在是只读的文本输入,因为它们是MySql表中的外键,但是我需要在php表中将它们看成文本才能知道数据。我想要的是能够同时编辑php表中的那些字段,并且需要下拉列表而不是文本输入: 1-他们需要默认当前数据,我希望能够从下拉列表中进行选择以将当前数据更改为其他数据。如果需要的话 *默认值应来自我要更新的表,但选择选项应来自外部表 2-而且我需要将该选择作为外键(整数)传递,以便能够更新MySql表
<body>
<!-- this is my table header-->
<table>
<thead>
<tr>
<th>Transaction Category</th>
<th>Transaction Group</th>
<th>Transaction Name</th>
<th>Amount</th>
<th>Date from</th>
<th>Date to</th>
<th>Notes</th>
</tr></thead>
<?php
//this is my form/Table
if (mysqli_num_rows($result2) > 0 ){
while($row = mysqli_fetch_assoc($result2)){
echo '<tr><form method="post">';
echo '<td><input type="text" name="transCat['.$row["budgetEstimatedId"].']" value="'.$row["transCat"].'" readonly="readonly"></td>';
echo '<td><input type="text" name="transGroup['.$row["budgetEstimatedId"].']" value="'.$row["transGroup"].'" readonly="readonly"></td>';
echo '<td><select name="transGroup['.$row["budgetEstimatedId"].']" >';
while($row1 = mysqli_fetch_assoc($result3)){
echo '<option value='.$row1["transGroupsId"].'" if('.$row1["transGroup"].'=='.$row1["transGroupsId"].' selected="selected")>'.$row1['transGroup'].'</option>';
}
echo '</select></td>';
echo '<td><input type="text" name="transNames['.$row["budgetEstimatedId"].']" value="'.$row["transNames"].'" readonly="readonly"></td>';
echo '<td><input type="decimal" name="amount['.$row["budgetEstimatedId"].']" value="'.$row["amount"].'"> </td>';
echo '<td><input type="date" name="dateFrom['.$row["budgetEstimatedId"].']" value="'.$row["dateFrom"].'"></td>';
echo '<td><input type="date" name="dateTo['.$row["budgetEstimatedId"].']" value="'.$row["dateTo"].'"> </td>';
echo '<td><textarea name="notes['.$row["budgetEstimatedId"].']"cols=34 rows=2 wrap=soft>'.$row["notes"].'</textarea> </td>';
echo '<td><input type="hidden" name="budgetEstimatedId[]" value="'.$row["budgetEstimatedId"].'"></td>';
}
echo '<input type="submit" name="submit" value="Multiple CHANGE">';
echo '<td><input type="submit" name="submit" value="Multiple CHANGE">';
echo '</form></tr>';
}
?>
</table>
</body>
<?php
//this is where the insert start
if(isset($_POST["submit"]))
{
foreach($_POST["budgetEstimatedId"] AS $budgetEstimatedIdID){
$amountID = $_POST["amount"][$budgetEstimatedIdID];
$dateFromID = $_POST["dateFrom"][$budgetEstimatedIdID];
$dateToID = $_POST["dateTo"][$budgetEstimatedIdID];
$notesID = $_POST["notes"][$budgetEstimatedIdID];
$update = "UPDATE budgetestimated SET amount='$amountID', dateFrom='$dateFromID', dateTo='$dateToID', notes='$notesID' WHERE budgetEstimatedId='$budgetEstimatedIdID' LIMIT 1";
mysqli_query($con, $update) or die (mysqli_error());
}
}
?>