<?php
class TableInfo extends CI_Model{
public function __construct(){
$this->load->database();//加载连接操作数据库
}
/*
==================================
查询分页数据
==================================
*/
// 显示分页
public function getConfig($url,$total_rows,$per_page)
{
$config['base_url'] =$url;
$config['total_rows'] =$total_rows;
$config['per_page'] =$per_page;
$config['num_links'] = 2; // 一些“数字”后,当前浏览的页面的链接显示在\ /
$config['use_page_numbers'] = TRUE; // 使用页面数段而不是偏移
$config['next_link'] = '下一页';
$config['prev_link'] = '上一页';
$config['first_link'] = '首页';
$config['last_link'] = '末页';
$config['uri_segment'] = 4;
$config['page_query_string'] = TRUE;
return $config;
}
//
/*使用
* $pagesize=8;
$page=isset($_GET['per_page'])?$_GET['per_page']:1;//页码被默认 pageINdex
$ai=isset($_GET['ai'])?$_GET['ai']:"";//传的参数
$this->load->library('pagination'); //应用page类
//$config['base_url'] ="/index.php/news/index?ai=aini"; //传多个值
//$config['total_rows'] = $this->news_model->get_count(); //总记录
//$config['per_page'] =$pagesize; //每页显示多少条
*
$url="/index.php/news/index?ai=aini";
$total_rows=$this->news_model->get_count();
$per_page=$pagesize;
$config=$this->news_model->Fen($url,$total_rows,$pagesize);
$this->pagination->initialize($config); //
echo $this->pagination->create_links();//输入分页样式
*/
/*
==================================
查询数据
==================================
*/
public function TableAll($table,$type="",$pageSizi=0,$pageIndex=0)
{
$query="";
if($type!="")
{
if($pageSizi!=0&&$pageIndex!=0)
{
$limit=$pageSizi*($pageIndex-1);
$query=$this->db->get($table,$pageSizi,$limit);
}
else
{
$query=$this->db->get($table);
}
return
$query->result_array();//获取该表的内容集合
}
else
{
$query=$this->db->get($table);
return
$query->num_rows();//获取该表的记录条数
}
return false;
}
public function sqlAll($sql,$type="",$debug=false)
{
if($debug==true)
{
echo $sql;
exit();
}
if($type!="")
{
$query=$this->db->query($sql);
return $query->result_array();
}
else
{
$query=$this->db->query($sql);
return $query->num_rows();
}
}
/*
==================================
添加数据
==================================
*/
public function TableAdd($table,$data,$debug=false)
{
$sql="";
if($data!=null)
{
$sql=$this->db->insert_string($table,$data);
}
if($debug==true)
{
echo $sql;//
exit();
}
$result=$this->db->query($sql);
if($result)
{
return true;
}
else
{
return false;
}
return false;
}
public function sqlAdd($sql,$debug=false)
{
if($debug==true)
{
echo $sql;
exit();
}
if($sql!="")
{
$res=$this->db->query($sql);
if($res)
{
return true;
}
else
{
return false;
}
}
return false;
}
/*
==================================
修改数据
==================================
*/
public function TableUp($table,$data,$where,$debug=false)
{
$sql="";
if($data!=null)
{
$sql=$this->db->update_string($table,$data,$where);
}
if($debug==true)
{
echo $sql;
exit();
}
$res=$this->db->query($sql);
if($res)
{
return true;
}
else
{
return false;
}
}
public function sqlUp($sql="",$debug=false)
{
if($debug==true)
{
echo $sql;
exit();
}
if($sql!="")
{
$res=$this->db->query($sql);
if($res)
{
return true;
}
else
{
return false;
}
}
}
/*
==================================
删除数据
==================================
*/
public function TableDel($table,$ziduan="",$value="")
{
if($ziduan!=""&&$value!="")
{
$this->db->where($ziduan,$value);
$res=$this->db->delete($table);
if($res)
{
return true;
}
else
{
return false;
}
}
}
public function sqlDel($sql,$debug=false)
{
if($debug==true)
{
echo $sql;
exit();
}
if($sql!=null)
{
$res=$this->db->query($sql);
if($res)
{
return true;
}
else
{
return false;
}
}
}
/*
==================================
获取一条数据
==================================
*/
public function TableRow($table,$data)
{
if($data!=null)
{
$query=$this->db->get_where($table,$data);
return $query->row_array();
}
}
}