[英]php codeigniter select data
我有一個在mysql工具中運行的查詢命令。
SELECT * FROM t_table1 WHERE id=18888
但是,當嘗試在php codeigniter中執行此命令時,不返回任何行。 我試圖獲取日志過程:
$report = array();
$report['sql'] = $this->db->last_query();
$report['error'] = $this->db->_error_number();
$report['message'] = $this->db->_error_message();
$report['aff_row'] = $this->db->affected_rows();
print_r($report);
沒有錯誤消息,但affected_rows = 0
;
但是這些行是在一個函數中的,有時它是有效的,但是當我嘗試更改數據庫時,它將不起作用。
請幫忙..
你可以試試看
$this->db->select('*');
$this->db->where('whatever');
$query = $this->db->get('table');
$num = $query->num_rows();
您正在從數據庫中選擇並檢查受影響的行,該行不會給您計數。 Affected_rows()
用於更新和刪除命令
嘗試使用
$this->db->from('yourtable');
[... more active record code ...]
$query = $this->db->get();
$rowcount = $query->num_rows();
使用num_rows()
獲取未獲取的行數
嘗試此查詢,希望它有用。
$result = $this->db->get_where('table_name',array('id'=>'1888'));
echo $result->num_rows();
試試這2行代碼
$result = $this->db->where('id', 18888)->get(t_table1)->num_rows();
var_dump($result);
在控制器中:
$id=18888; $this->data['get_results'] = $this->your_name_model->get_all_by_id($id);
在模型中:
public function get_all_by_id($id){
$this->db->select('*');
$this->db->from('t_table1');
$this->db->where('id',$id);
$query = $this->db->get();
return $query->result_array();
}
鑒於:
<?php foreach($get_results as $result): echo $result['id']; ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.