关于ECSHOP的会员列表问题,请高手忙一下

2016-07-07 15:00 来源:www.chinab4c.com 作者:ecshop专家

要用关联查询,只帮你改一个sql查询语句,供你参考:
  1. $sql = "SELECT user_id, is_shenhe,user_name,user_admin, email, is_validated, user_money, frozen_money, rank_points, pay_points, reg_time ".
  2. " FROM " . $GLOBALS['ecs']->table('users') . $ex_where .
  3. " ORDER by " . $filter['sort_by'] . ' ' . $filter['sort_order'] .
  4. " LIMIT " . $filter['start'] . ',' . $filter['page_size'];
复制代码
  1. $sql = "SELECT u.user_id, u.is_shenhe,u.user_name,u.user_admin, u.email, u.is_validated, u.user_money, u.frozen_money, u.rank_points, u.pay_points, u.reg_time ".
  2. " FROM " . $GLOBALS['ecs']->table('users') . " as uleft join " . $GLOBALS['ecs']->table('users') . " as a on a.user_id=u.user_admin $ex_where .
  3. " ORDER by " . $filter['sort_by'] . ' ' . $filter['sort_order'] .
  4. " LIMIT " . $filter['start'] . ',' . $filter['page_size'];
复制代码
共它的条件前要加上u. 或a.这样的表的别名前缀

回答:
怎么需要那么复杂呢

$sql = "";

$where= '';

if(id不为空){
$where.=" and id = id"
;
}

$sql.=" select要查的数据$where" 就可以了。思路就是这样

谢谢。

我的意思,在读取表USERS的时候,根据user_admin字段与 admin_user中user_id 关联,然后也把admin_user 表中的user_name 数据也读出来,及如何调用。
2楼的方式好象是可以,但我不懂调用,能否帮忙一下,谢谢……

有点深奥,等高手来解读。

顶一下,求助..

有点深奥,等高手来解读。

$sql = "SELECT u.user_id, u.is_shenhe,u.user_name,u.user_admin, u.email, u.is_validated, u.user_money, u.frozen_money, u.rank_points, u.pay_points, u.reg_time,a.user_name ".
" FROM " . $GLOBALS['ecs']->table('users') ."AS u LEFT JOIN ". $GLOBALS['ecs']->table('admin_user') ." AS a ON u.user_admin = a.user_id". $ex_where .
" ORDER by " . $filter['sort_by'] . ' ' . $filter['sort_order'] .
" LIMIT " . $filter['start'] . ',' . $filter['page_size'];


我这样修改语句,,但变成有两个USER_NAME ,如何区分出是,会员的USER_NAME ,还是管理员的USER_NAME, 模版我是这样调用的{user.user_name}

$filter = page_and_size($filter);
$sql = "SELECT u.user_id, u.is_shenhe,u.user_name,u.user_admin, u.email, u.is_validated, u.user_money, u.frozen_money, u.rank_points, u.pay_points, u.reg_time,a.user_name as admin_name ".
" FROM " . $GLOBALS['ecs']->table('users') ."AS u LEFT JOIN ". $GLOBALS['ecs']->table('admin_user') ." AS a ON u.user_admin = a.user_id". $ex_where .
" ORDER by " . $filter['sort_by'] . ' ' . $filter['sort_order'] .
" LIMIT " . $filter['start'] . ',' . $filter['page_size'];


问题解决了.呵呵 ..谢谢大家.