Now the mall class app or shopping site generally in addition to shopping, but also played a role in promotion, publicity and distribution, multi-level query is generally used in recursive and circular way. However, many beginners are not clear how to achieve, the following is a 20-level example, the code and run the results are as follows:
1.PHP query for each level number.
The PHP code is as follows:
$aim ["Prevtel"] = $tel;
$n=0; $array_co = array(); while ( $n< 10) { $users=M(‘user‘)->where($aim)->getField(‘tel‘,true); $aims[‘prevtel‘] = array(‘in‘,$users); $array_co[] = count($users).""; $user2=M(‘user‘)->where($aims)->getField(‘tel‘,true); $array_co[] = count($user2).""; $aim[‘prevtel‘] = array(‘in‘,$user2); $n++; } return $array_co;
2.php querying each level of personal information
The PHP code is as follows:
$aim ["prevtel"] = ' 15639743913 ';
$n=0; $array_co = array(); while ( $n< 10) { $users=M(‘user‘)->where($aim)->select(); $users1=array(); foreach ($users as $key => $value) { $users1[]=$value[‘tel‘]; } $aims[‘prevtel‘] = array(‘in‘,$users1); $array_co[] = $users; $user2=M(‘user‘)->where($aims)->select(); $users2=array(); foreach ($user2 as $k => $v) { $users2[]=$v[‘tel‘]; } $array_co[] = $user2; $aim[‘prevtel‘] = array(‘in‘,$users2); $n++; } var_dump($array_co);
Well, to this end, if you follow the test run, you should see the results, that more levels of the query is the same truth, if you still have questions, you can leave a message to consult, we can discuss mutual learning and progress.
This article by the Professional Zhengzhou app development company Brigitte Xuan Science and Technology finishing release, original is not easy, if need reprint please indicate source!
Multi-level queries in PHP are recursive and iterative in a detailed way