[英]How to call or show table that have column name contains bracket in php?
我無法調用具有包含方括號()的列的表。
如何調用表,我可以為列名加上別名嗎?
包含方括號的表是材料詳細信息,列是Panjang(mm)和Lebar(mm)
我的控制器:
public function GetDataID()
{
$id = $this->input->post('id');
$cek = $this->list->getDetailBagJob2($id);
if ($cek->num_rows() == 0) {
$bagianjob = $this->list->getDetailBagJob1($id)->result();
echo json_encode($bagianjob);
} else {
$bagianjob = $this->list->getDetailBagJob2($id)->result();
echo json_encode($bagianjob);
}
}
我的模特:
public function getDetailBagJob1($id)
{
$this->db->from('opdetailbagianjob');
$this->db->join('mbagianjob', 'opdetailbagianjob.ID_Bagian_Job=mbagianjob.ID_Bagian_Job');
$this->db->join('mmaterial', 'opdetailbagianjob.ID_Gramatur=mmaterial.ID_Material');
$this->db->join('mmaterial_type', 'opdetailbagianjob.ID_Bahan=mmaterial_type.ID_Mat_Type');
$this->db->join('mmaterialdetail', 'opdetailbagianjob.ID_Ukuran=mmaterialdetail.ID_Mat_Detail');
$this->db->where('No_Enquiry', $id);
return $this->db->get();
}
public function getDetailBagJob2($id)
{
$this->db->select('opdetailbagianjob.*,opdetailbagianjob.Keterangan as keteranganbagjob,mbagianjob.*,mmaterial.*,mmaterial_type.*,mmaterialdetail.*');
$this->db->from('opdetailbagianjob');
$this->db->join('mbagianjob', 'opdetailbagianjob.ID_Bagian_Job=mbagianjob.ID_Bagian_Job');
$this->db->join('mmaterial', 'opdetailbagianjob.ID_Gramatur=mmaterial.ID_Material');
$this->db->join('mmaterial_type', 'opdetailbagianjob.ID_Bahan=mmaterial_type.ID_Mat_Type');
$this->db->where('No_Enquiry', $id);
return $this->db->get();
}
我的Ajax要在控制台中調用響應:
function ambilenquiry(id) {
$.ajax({
url: "<?php echo base_url(); ?>Enquiry/GetDataID",
type: "POST",
dataType: "json",
data: {
"id": id
},
success: function(data) {
console.log(data);
},
error: function(data) {
alert('Gagal');
}
});
}
我希望輸出是成功響應,但是響應顯示錯誤
jquery-3.4.1.min.js:2 POST http://10.3.1.10:81/gapcalc/Enquiry/GetDataID 500(內部服務器錯誤)
就像我在評論中多次說過的那樣,對那些包含破折號,空格,括號等的列名使用反引號作為標識符,以便可以進行有效的查詢。
將它與->select
方法上的false
標志結合使用,以便它允許您使用原始輸入並允許那些反引號。
$this->db->select('
`mmaterial.Lebar(mm)`,
`mmaterial.Panjang(mm)`
', false);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.