$table
$table :
我的关注
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
/**
* 我的关注
* */
class Userfollow_model extends CI_Model
{
private $table ='userfollow';
private static $DB;
public function __construct()
{
parent::__construct();
self::$DB = $this->load->database('tanqinba', TRUE);
}
public function _sql($sql){
$query = self::$DB->query($sql);
$row = $query->result();
$row = json_decode(json_encode($row),true);
return $row;
}
/**
* 关注我的人 (粉丝)
* */
public function getMyfollowCount( $userId )
{
self::$DB->where('followUserId',$userId);
self::$DB->where('status',1);
return self::$DB->count_all_results( $this->table );
}
/**
* 添加
* */
public function insertData($followData)
{
$res = self::$DB->insert($this->table, $followData);
return $res;
}
/**
*获取单条数据
* */
public function getUserFollowRow($userId=0,$followUserId=0)
{
self::$DB->where('userId', $userId);
self::$DB->where('followUserId', $followUserId);
// $this->db->where('status', 1);
$result = self::$DB->get($this->table);
return $result->row_array();
}
/**
* 修改
* */
public function setUserFollowByID($updateData, $followId)
{
self::$DB->where('followId', $followId);
return self::$DB->update($this->table, $updateData);
}
/**
* 获取我关注的人
* */
public function getMyFollowUserId( $userId =0 )
{
self::$DB->where('userId',$userId);
self::$DB->where('status',1);
$result = self::$DB->get($this->table);
return $result->result_array();
}
/**
* 获取我关注的人
* */
public function getMyFollowUserList($type=0, $userId =0 ,$limit=10,$start=0)
{
if($type==0)
{
self::$DB->where('userId',$userId);
}
else
{
self::$DB->where('followUserId',$userId);
}
self::$DB->where('status',1);
self::$DB->order_by('createTime','desc')->limit($limit, $start);;
$result = self::$DB->get($this->table);
return $result->result_array();
}
public function getMyFollowUserCount($type=0, $userId =0)
{
if($type==0)
{
self::$DB->where('userId',$userId);
}
else
{
self::$DB->where('followUserId',$userId);
}
self::$DB->where('status',1);
return self::$DB->count_all_results( $this->table );
}
/**
* 获取我的粉丝新加的数量
* */
public function getMyFollowAddUserCount($type=0, $userId =0)
{
if($type==0)
{
self::$DB->where('userId',$userId);
}
else
{
self::$DB->where('followUserId',$userId);
}
self::$DB->where('readTime',0);
self::$DB->where('status',1);
return self::$DB->count_all_results( $this->table );
}
}
?>