时间:2021-07-01 10:21:17 帮助过:22人阅读
$sql = "SELECT b.a_id ". "FROM " .$GLOBALS['ecs']->table('B'). " AS b ". "LEFT JOIN " .$GLOBALS['ecs']->table('A'). " AS a ". "ON a.id IN(b.in_id) ". "WHERE b.shop_id = '15' AND a.attr_type = '1' " . "ORDER BY b.a_id DESC"; $row = $GLOBALS['db']->getAll($sql);
没看明白结果是怎么来的,猜测一下
create temporary table A (id int, attr_type int);insert into A values (15, 1),(14, 0),(13, 1),(12, 1); create temporary table B (a_id int, in_id int, shop_id int);insert into B values (400, 15, 15),(399, 15, 15),(388, 14, 15) ,(387, 14, 15),(386, 13, 15),(385, 13, 15),(384, 12, 15) ,(383, 12, 15),(384, 12, 14),(383, 12, 14) ,(382, 12, 14),(381, 12, 14),(380, 12, 14);select shop_id, group_concat(a_id) as attr_id from A, B where A.id=B.in_id and A.attr_type=1 group by shop_id, B.in_id
shop_id attr_id 14 384,383,382,381,380 15 384,383 15 386,385 15 400,399
结果就是 我浏览器给与 ....&shop_id=15 这个格局 php收到指令 从b表获取shop_id为15的数据 然后从b表隔离掉 attr_type 不是1的数据
获取到的应该是 以下几组
B表: 关键字段 a_id(字段id) in_id(同A表ID 关联)shop_id(获取依据字段 id)
400 15 15
399 15 15
386 13 15
385 13 15
384 12 15
383 12 15
然后归类 以 in_id 区分
400 15 15
399 15 15
*********************************************************************************************************************一个分组
386 13 15
385 13 15
*********************************************************************************************************************一个分组
384 12 15
383 12 15
*********************************************************************************************************************一个分组
然后把 前面的 a_id 字段数据做组合变化 写入到c表 形成 400|386|384 这种
C表:关键字段 id(字段id) shop_id(同B表shop_id 关联)attr_id(循环出来的数值) 以下是我想得到的结果
1 15 400|386|384
2 15 400|386|385
C表 id 为 auto属性 shop_id 为我给与的id attr_id 就是组合出来的变化结果
结果就是 我浏览器给与 ....&shop_id=15 这个格局 php收到指令 从b表获取shop_id为15的数据 然后从b表隔离
写错了 应该是从A表帅选
结果就是 我浏览器给与 ....&shop_id=15 这个格局 php收到指令 从b表获取shop_id为15的数据 然后从 A表隔离
select in_id, shop_id, group_concat(a_id) as attr_id from A, B where A.id=B.in_id and A.attr_type=1 and shop_id=15 group by B.in_id
in_id shop_id attr_id 12 15 384,383 13 15 386,385 15 15 400,399
select in_id, shop_id, group_concat(a_id) as attr_id from A, B where A.id=B.in_id and A.attr_type=1 and shop_id=15 group by B.in_id
in_id shop_id attr_id 12 15 384,383 13 15 386,385 15 15 400,399
大神,请您帮个忙,怎么把这个表里的数据按照我的要求隔离出来
img_id 标示为1的 goods_id 261 attr_id 区分组的依据
最终的要求就是 输出
a= '584,583,582,581,580,579'
b= '578,577,576,575,574,573'
572和495不输出 因为img_id 不等于一 谢谢了
select goods_id, attr_id, groub_concat(goods_attr_id) from tbl_name where img_id=1 group by attr_id
$a = array('571','570');$b = array('569','568','567','566','565','564');$c = array('563','562','561','560','559');foreach(combineDika($a,$b) as $v){ $r[] = join('|', $v);}$attr_all = join(',', $r);$attr_all = explode(',', $attr_all);foreach ($attr_all as $list){ $sql = "SELECT goods_attr " . "FROM " .$GLOBALS['ecs']->table('products') . "WHERE goods_attr = '".$list."' "; $check_attr = $GLOBALS['db']->getOne($sql); $value = 'ECS000261g_p'.rand(10000,99999); if (empty($check_attr)) { $sql = "INSERT INTO " . $GLOBALS['ecs']->table('products') . " (goods_id, goods_attr, product_sn, product_number) VALUES ('261', '".$list."', '$value', '10000')"; $GLOBALS['db']->query($sql); }}
用个2B方法读取出来了
谢谢版主
我现在结贴