TP⾥leftjoin实例操作
W ⽅法的参照实物: blog.sina/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
<span ><span >select * from user wher id in (1,2,5);
</span></span><ol><li>$where[‘name’] = array(‘like’, ‘%thinkphp%’);</li><li>$where[‘title’] = array(‘like’,’%thinkphp%’);</li><li>$where[‘_logic’] = ‘or';</li><li>$map[ (id>1)AND( (namelike’%thinkphp%’)OR(titlelike’%thinkphp%’) )
<span >www.unphp/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 ->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.ver_id,e.ate_time,e.update_aveldays,e.begincity')
->where("f.siteid=".SITEID." and e.t_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
sql left 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->lis
<?php
//开启调试模式
define('APP_DEBUG', true);
//加载框架⼊⼝⽂件
require './ThinkPHP/ThinkPHP.php';
<span><?php if(!empty($balance)):?>¥{$al}元<?php else:?>¥0 元<?php endif;?></span></label>
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();
->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('id=meet.id and company.categoryid=category.id') ->field('company.* , meet.title , category.category')
->order('id desc')
->select();
</span>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论