W 方法的参照实物: http://blog.sina.com.cn/s/blog_68b4ec9b0101e225.html
SELECT a.id,goods_name,goods_ico,goods_introduct,tox_money_need,market_price,goods_num,changetime,STATUS,createtime,category_id,is_new,sell_num
FROM`thinkox_shop` AS a , `thinkox_shop_see` AS b WHERE ( b.`uid` =1000 )
AND ( b.`goods_id` <> '1' ) AND ( a.`status` = 1 )
AND(a.`id` =b.`goods_id`) ORDER BY b.update_time DESC LIMIT 3
select * from user wher id in (1,2,5);
- $where[‘name’] = array(‘like’, ‘%thinkphp%’);
- $where[‘title’] = array(‘like’,’%thinkphp%’);
- $where[‘_logic’] = ‘or';
- $map[‘_complex’] = $where;
- $map[‘id’] = array(‘gt’,1);
查询条件是
(id>1)AND( (namelike’%thinkphp%’)OR(titlelike’%thinkphp%’) )
http://www.unphp.com/index.php/page/3
D('websit')->where('siteid ='.$CountUid)->getField('uid');
D('websit')->create($data);
$addsiteid=D('websit')->add();
$count=D('websit')->where($map_str)->count();
$bb=D('websit')->count('uid');
$group_user=D('Member')->field('is_use,checked')
->where("uid=$uid and is_use>1")
->find();
$list=D('member_personal')->where("uid=$uid")->find();
$check_url=D('websit')->where("url='{$url}' and siteid !=".$siteid)->find();
用户资料两表连查*/
private function data($uid){
$data_user=D('thinkox_member');
return $data=$data_user->Table(array('thinkox_member'=>'m','thinkox_ucenter_member'=>'u'))
->field('m.uid,m.nickname,m.qq,m.score,m.signature,m.pos_province,m.pos_city,m.pos_district,m.is_use,m.pos_community,m.self_introduction,m.sex,m.telphone,m.real_name,u.email,u.username')
->where("m.uid=u.id and m.uid=$uid")
->find();
}
if(!empty($uid)){
$mark=D('thinkox_forum_bookmark'); //---
$list=$mark->Table(array('thinkox_event'=>'e','thinkox_forum_bookmark'=>'f'))
->field('e.id,e.uid,e.cover_id,e.title,e.create_time,e.update_time,e.traveldays,e.begincity')
->where("f.siteid=".SITEID." and e.id=f.content_id and f.uid=$uid")
->select();
$this->assign('list',$list);
}
做一个左连接,第一个表为Comment表,第二个表为Reply表,
MYSQL上测试语句为:select a.*,b.* from comment a left join reply b on a.id=b.cid
//Left Join
$Blog->table('comment a')->join('reply b on a.id=b.cid')->field('a.*,b.*')->order('id desc')->limit('8')->findall();
//Right Join
$Blog->table('comment a')->join(array('right','reply b on a.id=b.cid'))->field('a.*,b.*')->order('id desc')->limit('8')->findall();
$Admin =M('Admin');
$Re = $Admin -> join('LEFT JOIN sx_user ON sx_user.UID = sx_admin.AUID') -> select();
**********************************
$M = M();
$r = $M->query("select * from sx_admin LEFT JOIN sx_user ON sx_admin.AUID = sx_user.UID");
此处加入了:前缀:
$model = M("Admin");
$admin_list = $model->alias("m")->join(C('DB_PREFIX').'gadmin c ON m.admin_gid=c.gid','LEFT')->order('m.admin_id desc')->limit($page->firstRow.','.$page->listRows)->select();
¥{$balance.total}元¥0 元
echo M("member")->getLastSql();
'SHOW_PAGE_TRACE'=>true,
SELECT bb FROM aa WHERE (id=1); 取出id为1的所有 bb 字段信息
$table=M('表名');
$where['id'] = 1; //这样写比较好,数组形式,2个where相当于 id=1 and ..
$list=$table->field('bb')->where($where)->select();
echo $table->getlastsql(); //输出最后查询的一句SQL 一般校验SQL错误都是从这里来的
$this->assign('list',$list);
$this->display('templates_name');
$goods_list=D('shop_order_info')
->field('*')
->where(array('order_sn'=>$order_sn,'uid'=>is_login(),'siteid'=>SITEID,'a.id'=>'b.good_id'))
->table('shop_order_info a,shop b')
->select();
//如果需要进行分页的话,和平时操作一样,没有区别
$Model=new Model();
$this->companyList=$Model
->table(array(
C('DB_PREFIX').'company'=>'company',
C('DB_PREFIX').'meet'=>'meet',
C('DB_PREFIX').'category'=>'category',
)
)
->where('company.meetid=meet.id and company.categoryid=category.id')
->field('company.* , meet.title , category.category')
->order('company.meetid desc')
->select();