1、无限查询用户上级在注册的时候就把注册的uid存在设计好的数据表里面。 if(IS_POST){ $tjphone=arg('tjphone',''); $mobile=arg('mobile',''); $realname=arg('realname',''); $yaoqingma=arg('yaoqingma',''); $yzm=arg('yzm',''); $password=arg('password',''); $repassword=arg('repassword',''); if(empty($realname)){ $msg['status']=0;$msg['msg']='请输入真实姓名';echo json_encode($msg);exit; } if(empty($mobile)){ $msg['status']=0;$msg['msg']='请输入手机号';echo json_encode($msg);exit; } if(empty($password)){ $msg['status']=0;$msg['msg']='请输入登录密码';echo json_encode($msg);exit; } if(strlen($password)>16 || strlen($password)<6){ $msg['status']=0;$msg['msg']='登录密码必须(6-16)位数字字母组合';echo json_encode($msg);exit; } if($password!=$repassword){ $msg['status']=0;$msg['msg']='两次密码输入不一致';echo json_encode($msg);exit; } $usere=get_onerecord(array('username'=>$mobile), 'user', 'uid'); if($usere){ $msg['status']=0;$msg['msg']='手机号已存在';echo json_encode($msg);exit; } $usere=get_onerecord(array('telephone'=>$mobile), 'user', 'uid'); if($usere){ $msg['status']=0;$msg['msg']='手机号已存在';echo json_encode($msg);exit; } $res = get_model_one(array('verify'=>$yzm), 'shortmsg','*'); if($res){ if ($res['period'] > time()) { $data['username']=$mobile; $salt=get_rand_char(4); $data['password']=md5($salt.$password); $data['salt']=$salt; $data['telephone']=$mobile; $data['joindate']=time(); $data['joinip']=getip(); $data['isadmin']=0; $data['issup']=0; $data['status']=1; $data['logintype']=1; $re=create_record($data, 'user'); if($re){ $shop_userinfo=get_model_one(array('uid'=>$re), 'user'); set_admin_info($shop_userinfo,'shop_userinfo'); $user_pre_data['uid']=$re; $user_pre_data['realname']=$realname; $user_pre_data['createtime']=time(); $user_pre_data['nickname']=''; $user_pre_data['telephone']=$mobile; $user_pre_data['kaihuhang']=''; $user_pre_data['kaihukahao']=''; $user_pre_data['idcard']=''; $user_pre_data['dodanuid']=0; $shopinfo=get_model_one(array(), 'shop'); $config=json_decode($shopinfo['config'],true); $tjinfo=get_model_one(array('username'=>$tjphone), 'user'); if(!$tjinfo && $_SESSION['web_puid']){ $tjinfo=get_model_one(array('uid'=>$_SESSION['web_puid']), 'user'); } if($tjinfo){ $tjinfo=get_model_one(array('uid'=>$tjinfo['uid']), 'user_profile'); $recommendation=$tjinfo['uid']; $ceng=$tjinfo['ceng']+1; $keystring=$tjinfo['keystring'].$re.','; }else{ $ceng=0; $recommendation=0; $keystring=','.$re.','; } $user_pre_data['recommendation']=$recommendation; $user_pre_data['keystring']=$keystring; $user_pre_data['ceng']=$ceng; $user_pre_data['dengji']=0; $user_pre_data['pointsmax']=200; $user_pre_data['points']=0; $reuid=create_record($user_pre_data, 'user_profile'); if($recommendation){ hb_regist_user($user_pre_data['uid']); } $msg['status']=1;$msg['msg']='注册成功'; $msg['url']=url('shopping/wap','usercenter'); echo json_encode($msg);exit; }else{ $msg['status']=0;$msg['msg']='报单失败请重试';echo json_encode($msg);exit; } }else{ $msg['status'] = 0; $msg['msg'] = '验证码过期'; echo json_encode($msg); exit; } }else{ $msg['status'] = 0; $msg['msg'] = '验证码错误'; echo json_encode($msg); exit; } 2、查找当前用户的所有上级 $userinfo_a=get_model_one(array('uid'=>16),'user_profile'); $userlist=get_model_other(array('uid in (0'.$userinfo_a['keystring'].'0)'), 'user_profile','uid,recommendation,keystring,dengji');