Advertisement
harensarma

Untitled

Feb 4th, 2023
920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.20 KB | None | 0 0
  1. <?php
  2. function recursive_member_pool_find_d($id) /// $id is the reffer id.
  3.     {
  4.     //// here table name is Member, and A meand leg_a, B means leg_b, C means leg_c and D means leg_d and serial is autoincrement value of the database.
  5.         $result = Member::select('id', 'A', 'B', 'C', 'D')->where('id', $id)
  6.                         ->where(function ($query) {
  7.                             $query->where('A', '0')
  8.                                   ->orWhere('B', '0')
  9.                                   ->orWhere('C', '0')
  10.                                   ->orWhere('D', '0');
  11.                         })
  12.                         ->orderBy('serial', 'ASC')
  13.                         ->first();
  14.         if (empty($result)) {
  15.             $result = Member::select('id', 'A', 'B', 'C', 'D')->where('position', $id)
  16.                             ->where(function ($query) {
  17.                                 $query->where('A', '0')
  18.                                       ->orWhere('B', '0')
  19.                                       ->orWhere('C', '0')
  20.                                       ->orWhere('D', '0');
  21.                             })
  22.                             ->orderBy('serial', 'ASC')
  23.                             ->first();
  24.         }
  25.         if ($result->A == 0) {
  26.             return [
  27.                 'position' => $result->id,
  28.                 'leg'      => 'A',
  29.             ];
  30.         } else if ($result->B === 0) {
  31.             return [
  32.                 'position' => $result->id,
  33.                 'leg'      => 'B',
  34.             ];
  35.         } else if ($result->C === 0) {
  36.             return [
  37.                 'position' => $result->id,
  38.                 'leg'      => 'C',
  39.             ];
  40.         } else if ($result->D === 0) {
  41.             return [
  42.                 'position' => $result->id,
  43.                 'leg'      => 'D',
  44.             ];
  45.         } else {
  46.             $data = Member::select('id')->where('position', $id)->orderBy('serial', 'ASC')->get();
  47.             foreach ($data as $result):
  48.                 if ($result->id !== $id):
  49.                     return recursive_member_pool_find_d($result->id); /// calling the same function
  50.                 endif;
  51.             endforeach;
  52.         }
  53.     }
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement