$table
$table :
Model Class
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Singer_model extends CI_Model{
private $table='singer'; //表名
//查询
public function check($where){
if (!is_array($where)){
return false;
}
$this->db->where($where);
$res=$this->db->get($this->table)->result_array();
return $res;
}
//查找全部
public function check_all(){
$res=$this->db->get($this->table)->result_array();
return $res;
}
public function show_home(){ //首页住家展示
$this->db->where('show_home',1);
$res=$this->db->get($this->table,8)->result_array();
return $res;
}
public function comment(){ //首页住家评论展示
$this->db->where('comment_show',1);
$res=$this->db->get($this->table)->result_array();
return $res;
}
//修改
public function update($id,$data){
$data['updatetime']=time();
$this->db->where('id',$id);
$this->db->update($this->table,$data);
//返回影响的行数
$res=$this->db->affected_rows();
return $res;
}
//插入
public function add($data){
$data['createtime']=time();
$this->db->insert($this->table,$data);
$res=$this->db->insert_id();
return $res;
}
//删除
public function delete($id){
$this->db->where('id',$id)->delete($this->table);
$res=$this->db->affected_rows();
return $res;
}
//分页显示数据信息
public function page($start_position,$per_nums,$issue,$ser='',$city=''){
if(!empty($city)){ //筛选城市
$this->db->where('city',$city);
}
if(!empty($ser)){
$this->db->like('content',$ser);
}
$this->db->where('issue',$issue);
$data['total_nums']=$this->db->get($this->table)->num_rows();
if(!empty($city)){
$this->db->where('city',$city);
}
//如果是搜索,则like查询
if(!empty($ser)){
$this->db->like('content',$ser);
}
$this->db->where('issue',$issue);
$this->db->order_by('id','desc'); //倒序排列
$res=$this->db->get($this->table,$per_nums,$start_position)->result_array(); //分页获取文章列表数据
$data[]=$res; //这里大家可能看的有点不明白,可以分别将$data和$data2打印出来看看是什么结果。
return $data;
}
/**
* lxn 2017-7-12
* 查询单条数据
*/
public function getHouseRow($houseId = 0)
{
$this->db->where('id', $houseId);
return $this->db->get($this->table)->row_array();
}
}
?>