thinkphp3.2.3大神请进—多表关联 多条件查询

用户表 //用户类别表
the_comy_rem the_rem_type
字段:ID和the_rem_type 字段:t_r_t_id type name
================================================
$com=$_SESSION["com"] ; //登录的ID
$compy=M("the_comy_rem"); //用户表

$type=M("the_rem_type"); //用户类别表

$compyrow=$compy->where("ID='$com'")->select();
//查表里the_compyid 等于登录ID
$t_id=$compyrow["the_rem_type"];// the_comy_rem表下the_rem_type字段

$typerow=$type->where("t_r_t_id='$t_id'")->select();
+++++++++++++++++++++++++++++++++++++++++++++++++
$compyrow=$compy->where("ID='$com'")->select();
//查表里the_compyid 等于登录ID
$t_id=$compyrow["the_rem_type"];// the_comy_rem表下the_rem_type字段
$typerow=$type->where("t_r_t_id='$t_id'")->select();
在这里就是有两条 数据 , 我是 要查出用户登录的 团队(com) the_compyid,下的所有员工的的the_rem_type 。 用find() 可以输出但是 find()后 这两个员工the_rem_type 就都变成第一条的
已经解决$typerow = M()->table('the_rem_type as a')->join('the_comy_rem as b on b.the_rem_type = a.t_r_t_id')->where(" b.the_compyid = '$com'")->select();

对前台传来的商品id数组在表中进行查询
//$goods = array(11,10,7);
$where['goods_id']=array("in",$goods);
$where['user_id'] = $_SESSION['uid'];
$res = D("cart")->where($where)->select();
复制代码
得到sql语句如下
"SELECT * FROM `cart` WHERE `goods_id` IN (11,10,7) AND `user_id` = 1
温馨提示:答案为网友推荐,仅供参考
相似回答