Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function recursive_member_pool_find_d($id) /// $id is the reffer id.
- {
- //// 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.
- $result = Member::select('id', 'A', 'B', 'C', 'D')->where('id', $id)
- ->where(function ($query) {
- $query->where('A', '0')
- ->orWhere('B', '0')
- ->orWhere('C', '0')
- ->orWhere('D', '0');
- })
- ->orderBy('serial', 'ASC')
- ->first();
- if (empty($result)) {
- $result = Member::select('id', 'A', 'B', 'C', 'D')->where('position', $id)
- ->where(function ($query) {
- $query->where('A', '0')
- ->orWhere('B', '0')
- ->orWhere('C', '0')
- ->orWhere('D', '0');
- })
- ->orderBy('serial', 'ASC')
- ->first();
- }
- if ($result->A == 0) {
- return [
- 'position' => $result->id,
- 'leg' => 'A',
- ];
- } else if ($result->B === 0) {
- return [
- 'position' => $result->id,
- 'leg' => 'B',
- ];
- } else if ($result->C === 0) {
- return [
- 'position' => $result->id,
- 'leg' => 'C',
- ];
- } else if ($result->D === 0) {
- return [
- 'position' => $result->id,
- 'leg' => 'D',
- ];
- } else {
- $data = Member::select('id')->where('position', $id)->orderBy('serial', 'ASC')->get();
- foreach ($data as $result):
- if ($result->id !== $id):
- return recursive_member_pool_find_d($result->id); /// calling the same function
- endif;
- endforeach;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement