我是codeigniter的新手。请有人帮我解决这个问题。我想显示一个包含输入字段的表,以便用户可以插入数据并将其更新到数据库中。用户可以更改表中的所有数据。我想一次更新多行,但最终只更新1行(最后一行)。有人请帮助我。 Thnks。这是以下代码。
模型
public function add_order_data($itemcode, $qty, $supcode, $guid)
{
$sql1 = "SELECT * FROM stock_count INNER JOIN stock_count_item";
$query1 = $this->db->query($sql1);
$num = $query1->result();
for($i=0;$i<count($query1);$i++){
//data is retrive from this query
$sql = "UPDATE
stock_count,
stock_count_item,
po_ex_c
INNER JOIN po_ex ON po_ex_c.poex_guid = po_ex.poex_guid
SET stock_count.posted = '1',
stock_count_item.qty_order = '$qty[$i]',
po_ex_c.qty_actual = '$qty[$i]'
WHERE stock_count.TRANS_GUID = '$guid[$i]' AND
stock_count_item.Itemcode = '$itemcode[$i]' AND
po_ex_c.itemcode = '$itemcode[$i]' AND
stock_count_item.TRANS_GUID = '$guid[$i]' AND
po_ex.sup_code = '$supcode[$i]'";
$query = $this->db->query($sql);
}
return $query;
}
控制器
function add_order()
{
$qty = $this->input->post('qty');
$itemcode = $this->input->post('itemcode');
$supcode = $this->input->post('supcode');
$guid = $this->input->post('guid');
if ($this->input->post('save') == "save")
{
$result = $this->submit2_model->add_order_data($itemcode, $qty, $supcode, $guid);
if($result > 0)
{
redirect("home_c/viewdata");
echo "<script> alert('succesfully add');</script>";
}
else
{
redirect("submit2_c/viewdata");
echo "<script> alert('cannot add');</script>";
}
}
}
视图
<form class="form-inline" role="form" method="POST" id="myForm" action="<?php echo site_url('submit2_c/add_order'); ?>">
<td><input type="number" name="qty[]" value="" style="text-align:center;width:80px;" max="100000"/></td>
<td><?php echo $row->SupLastPrice; ?></td>
<td><?php echo $row->SupStdPrice; ?></td>
<td><?php echo $row->ads; ?></td>
<td><?php echo $row->ams; ?></td>
<td><?php echo $row->aws; ?></td>
<td><?php echo $row->doh; ?></td>
</tr>
</tbody>
<input type="" name="itemcode[]" value="<?php echo $row->Itemcode; ?>" style="text-align:center;width:80px;" max="100000"/>
<?php
}
?>
<input type="" name="supcode[]" value="<?php echo $_SESSION["supcode"]; ?>" style="text-align:center;width:80px;" max="100000"/>
<input type="" name="guid[]" value="<?php echo $_SESSION["guid"]; ?>" style="text-align:center;width:80px;" max="100000"/>
</table>
<div class="box">
<h5>ADS = <b>Average Daily Sales</b></h5>
<h5>AWS = <b>Average Weekly Sales</b></h5>
<h5>AMS = <b>Average Monthly Sales</b></h5>
<h5>DOH = <b>Daily On Hand</b></h5>
</div><br>
<button value="save" name="save" type="submit" class="btn btn-default btn-sm" style="margin-left: 0px;background-color:#00b359;width:70px;margin-right:8px">
<b>SUBMIT</b>
</button>
</form>