表结构:

代码:
查询包今$mid和$department_id的记录
$mid = cookie('mid');
$department_id = M('user')->where('id = ' . $mid)->getField('department_id');
if(!$type) {
//首次加载首页
$where = 'is_send = 1 and to_type = 1 or find_in_set(' . $mid . ',to_mid) or find_in_set(' . $department_id . ',to_department)';
} elseif ($type == 1) {
$new_id = I('post.new_li','','intval');
$where = 'id > ' . $new_id;
$where .= ' and (is_send = 1 and to_type = 1 or find_in_set(' . $mid . ',to_mid) or find_in_set(' . $department_id . ',to_department))';
} elseif($type == 2) {
$page = I('post.page',2,'intval');
$where = 'is_send = 1 and to_type = 1 or find_in_set(' . $mid . ',to_mid) or find_in_set(' . $department_id . ',to_department)';
}
$order = 'add_time desc';//is_top desc,
$list = M('notice')->where($where)->order($order)->page($page, $limit)->select();
本文介绍了一种基于SQL的查询方法,通过设置不同的变量如$mid和$department_id来实现对数据库表中特定记录的筛选。具体实现了根据不同类型的请求加载对应的数据记录,并通过$order参数确定返回结果的排序方式。
5641

被折叠的 条评论
为什么被折叠?



