2016-04-15 49 views
0

我有2個表:「Excel的」 enter image description here和「請求」 enter image description here發送Ajax值到MySQL

我從輸入文本的價值,現在我想將「9000」值發送到「雙人牀價格」字段'excel'表。

enter image description here

這是我的控制器:

<?php 
 
defined('BASEPATH') OR exit('No direct script access allowed'); 
 

 
class Ajax extends CI_Controller { 
 

 
\t function edit($excel_id, $tarif) 
 
\t { 
 
\t \t echo $excel_id; 
 
\t \t $this->load->model('request'); 
 
\t \t $this->request->updatedata($tarif,$excel_id); 
 

 
\t } 
 
}

我的模型:

<?php 
 
class Request extends CI_Model { 
 

 
\t function updatedata($id,$tarif) 
 
    { 
 
     $this->db->set('tariff', $tarif); 
 
     $this->db->where('excel_id',$id); 
 
     $query = $this->db->update('excel'); 
 
     return $query->result_array(); 
 
    } 
 
}

這是我的阿賈克斯,在視圖中:

!DOCTYPE html> 
 
<html> 
 
<head> 
 
\t <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> 
 

 
\t <table class="table"> 
 
\t \t <th> 
 
\t \t \t Alamat 
 
\t \t </th> 
 
\t \t <th> 
 
\t \t \t Tarif 
 
\t \t </th> 
 

 
<?php   
 
    foreach ($undg[$value['req']] as $row) {   
 
?> 
 
\t \t <tr> 
 
     <td><?php echo $row['alamat_tujuan']?></td> 
 
\t \t <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 }}; ?> 
 
\t \t </tr> 
 
\t </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>

我要發送的值 '9000',其輸入文本內到MySQL。我不知道語法

+0

有啥實際問題? – 2016-04-15 02:38:50

+0

我從ajax獲得'9000'值,並且我想將該值發送到一個字段 – Maii

回答

0

嘗試這樣

   $this->request->updatedata($excel_id,$tarif); 

代替

   $this->request->updatedata($tarif,$excel_id);