我有2个表:' excel' 和'请求'
我从输入文本中获取值,现在我想发送' 9000'价值进入' tarif'领域' excel'表
这是我的控制者:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Ajax extends CI_Controller {
function edit($excel_id, $tarif)
{
echo $excel_id;
$this->load->model('request');
$this->request->updatedata($tarif,$excel_id);
}
}
&#13;
我的模特:
<?php
class Request extends CI_Model {
function updatedata($id,$tarif)
{
$this->db->set('tariff', $tarif);
$this->db->where('excel_id',$id);
$query = $this->db->update('excel');
return $query->result_array();
}
}
&#13;
这是我的ajax,在视图中:
!DOCTYPE html>
<html>
<head>
<title>Admin Kirim Undangan</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<h3>Customer Request</h3>
<?php
foreach ($results as $value) {
?>
<table class="table">
<tr>
<td><?= $value['nama']?></td>
<td><?= $value['phone']; ?></td>
<td><?= $value['alamat_pengirim']?></td>
</tr>
</table>
<table class="table">
<th>
Alamat
</th>
<th>
Tarif
</th>
<?php
foreach ($undg[$value['req']] as $row) {
?>
<tr>
<td><?php echo $row['alamat_tujuan']?></td>
<td><input type="text" id="<?php echo $row['excel_id']?>" name="tarif"></input> <!-- id input text nya harus dibedakan berdasarkan excel_id -->
<?php form_open(); ?>
<button type="button" class="btn btn-primary btn-sm" onclick=update(<?php echo $row['excel_id']?>)>Update Tarif
</button>
</td>
<?php form_close(); ?>
<?php }}; ?>
</tr>
</table>
</body>
</html>
<script>
function update(excel_id) {
$.ajax({
type: "POST",
url: "<?php echo site_url('ajax/edit');?>/" + excel_id + "/" + $('#'+excel_id).val(),
data: $(this).serialize(),
dataType: 'json',
success: function (data) {
console.log(data);
}
});
};
</script>
&#13;
我想发送价值&#39; 9000&#39;其中输入文本里面的mysql。我不知道语法
答案 0 :(得分:0)
试试这个
$this->request->updatedata($excel_id,$tarif);
而不是
$this->request->updatedata($tarif,$excel_id);