PHP for loop thinking about problems

Source: Internet
Author: User
PHP for Loop thinking problem
I am a novice php, recently developed projects to find a binary tree system of Welfare award. The execution efficiency is too low after the completion of writing. Ask Master big God to point out the idea. Picture description
1. The performance of about 1W is the supervisor. Under the management system, there are 2 supervisors who are managers. Under the management system, there are 2 managers who are directors. 0 Members, 1 supervisors, 2 managers, 3 directors.
I wrote the following code:
Welfare Award begins
Unset ($MAP);//Destroy the map variable value
$map [' _string ']= ' DateDiff (Curday, ' ". $beginday.") <=0 ";
Check all member Performance
$hyyjlist = $hyyj->where ($map)->field (' Userid,sum (leftyj1) +sum (leftyj2) as Sumleft ')->group (' userid ')- >select ();
$glrCountArry =array ();//key: Executive Name+flrjl Value: An array of the number of persons holding the charge
foreach ($hyyjlist as $hkey + $hvalue) {//Cycle update user's supervisor benefits
if ($hvalue [' Sumleft ']>=10000) {
$US = $userListArry [$hvalue [' UserID ']];//3 membership based on ID
if ($US [' flstate ']==0) {//status is 0 members
if ($salary 1->where (' periods ' + $periods, ' userid ' = + $US [' ID ']))->setfield (' flj ' = ' Z Supervisor Award Content Z ')) (===false) {
$salary->rollback ();
$this->error (' Welfare Award update failed ');
}
For (!empty ($US [' gluser ']), $i =0; $i
if (!array_key_exists ($US [' Gluser ']. " Flrzg ", $glrCountArry)) {
$glrCountArry [$US [' Gluser ']. " Flrzg "]=1;
}else{
$glrCountArry [$US [' Gluser ']. " Flrzg "]+=1;
}
$US = $userNameListArry [$US [' Gluser '];
if (empty ($US)) {
$i =count ($userlist);
}
}
}
}
}
$find [' State ']=array (' eq ', 1);//Status =1 active
$find [' _string ']= "From_unixtime (confirmtime, '%y-%m-%d ') <= '". $beginday. "'"; /Activation Date Current time
$list 2= $users->where ($find)->select ();//Query Membership list
$glrCountArry 2=array ();//Key: Manager NAME+FLRJL Value: Number of people to save an array of managers
foreach ($list 2 as $key = + $value) {//Get Manager benefits
$US = $value;
if ($US [' flstate ']==1) {
For (!empty ($US [' gluser ']), $i =0; $i
if ($glrCountArry [$US [' username ']. " Flrzg "]>0" {//Member is the executive level, the number of executives in the array is greater than 0 update member's manager benefits
if ($salary 1->where (' periods ' + $periods, ' userid ' = + $US [' ID ']))->setfield (' flj ' = ' Z Manager Prize content z ')) ===false) {
$salary->rollback ();
$this->error (' Welfare Award update failed 2 ');
}
}
if (!array_key_exists ($US [' Gluser ']. " Flrjl ", $glrCountArry 2)) {//Make the member's top manager +1
$glrCountArry 2[$US [' Gluser ']. " Flrjl "]=1;
}else{
$glrCountArry 2[$US [' Gluser ']. " Flrjl "]+=1;
}
$US = $userNameListArry [$US [' Gluser '];
if (empty ($US)) {
$i =count ($userlist);
}
}
}else if ($value [' flstate ']==0) {//Membership level is not supervisor, number of supervisors is greater than 1 update member's manager benefits
For (!empty ($US [' gluser ']), $i =0; $i
if ($glrCountArry [$US [' username ']. " Flrzg "]>1" {//Member is the executive level, the number of executives in the array is greater than 0 update member's manager benefits
if ($salary 1->where (' periods ' + $periods, ' userid ' = + $US [' ID ']))->setfield (' flj ' = ' Z Manager Prize content z ')) ===false) {
$salary->rollback ();
$this->error (' Welfare Award update failed 2 ');
}
}
if (!array_key_exists ($US [' Gluser ']. " Flrjl ", $glrCountArry 2)) {//Make the member's top manager +1
$glrCountArry 2[$US [' Gluser ']. " Flrjl "]=1;
}else{
$glrCountArry 2[$US [' Gluser ']. " Flrjl "]+=1;
}
$US = $userNameListArry [$US [' Gluser '];
if (empty ($US)) {
$i =count ($userlist);
}
}

}
}
foreach ($list 2 as $key + $value) {//Get Director benefits
$US = $value;
if ($US [' flstate ']==2) {//status is 2 Manager
For (!empty ($US [' gluser ']), $i =0; $i
if ($glrCountArry 2[$US [' username ']. " Flrjl "]>0" {//member is manager level, manager array number is greater than 0 update member's director benefits
if ($salary 1->where (' periods ' + $periods, ' userid ' = + $US [' ID ']))->setfield (' flj ' = ' Z Director prize Content z ')) ===false) {
$salary->rollback ();
$this->error (' Welfare Award update failed 3 ');
}
}
$US = $userNameListArry [$US [' Gluser '];
if (empty ($US)) {
$i =count ($userlist);
}
}
}else if ($value [' flstate ']<2) {//status is not manager, as long as the number of managers array reaches 2 Update member's director benefits
For (!empty ($US [' gluser ']), $i =0; $i
if ($glrCountArry 2[$US [' username ']. " Flrjl "]>1" {//member is manager level, manager array number is greater than 1 update member's director benefits
if ($salary 1->where (' periods ' + $periods, ' userid ' = + $US [' ID ']))->setfield (' flj ' = ' Z Director prize Content z ')) ===false) {
$salary->rollback ();
$this->error (' Welfare Award update failed 3 ');
}
}
$US = $userNameListArry [$US [' Gluser '];
if (empty ($US)) {
$i =count ($userlist);
}
}
}
}
Welfare award Ends
------to solve the idea----------------------
What is the table structure? It should be done with the update command.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.