假設我有我的模型,此本機查詢:和我的控制器如何提取多個字段名稱/列值 - Codeigniter?
public function print_query($id){
$sql = "Select Field1,Field2,Field3.. FROM Table WHERE id = '".$id."' ";
if($this->db->query($sql, array($id))->num_rows() > 0)
{
return $this->db->query($sql, array($id))->result();
}
}
這樣的:
public function emp_preview(){
$EmpID = $this->input->post('txt_id');
$data['p_det'] = $this->db_sal_details->print_query($EmpID);
$this->load->view('employee/preview',$data,TRUE);
}
在我看來:我想顯示字段1,字段2,字段3的值,依此類推。, 我用這段代碼來顯示它們;
<table>
<tr>
<?php if($p_det):?>
<?php foreach($p_det as $det):?>
<th><?php echo $det->Field1;?></th>
<th><?php echo $det->Field2;?></th>
<th><?php echo $det->Field2;?></th>
...
<?php endforeach;?>
<?php endif;?>
</tr>
</table>
這是一切正常,顯示字段及其值。但是如果我不只有3個字段(例如50個字段),並且我想動態填充TH而不輸入每個字段。我怎樣才能做到這一點。,?
我知道這對你的專家很簡單,我。但我在這裏只是一個初學者..請容忍我,幫我這一個,提前任何答覆謝謝..
if($ this-> db-> query($ sql,array($ id)) - > num_rows()> 0) { return $ this-> db-> query($ sql,array($ id )) - >結果(); } 你在這裏運行查詢兩次btw – qwertzman