kosky2005

Experience

290

0 Best Reply Awards

  • Member Since 7 Months Ago
  • 0 Lessons Completed
  • 0 Favorites

14th March, 2018

kosky2005 left a reply on Loop Using Foreach In A Collection Where Contains • 6 months ago

i am getting this error

Call to undefined method stdClass::has() (View:

this is my code in view

    @foreach($getAll as $key => $group)
                {{$key}}

            @foreach($group as  $trans)

               <tr>
                   <td>
                       @if($trans->has('transCode'))
                           {{ $trans->transCode }}: {{ $trans->total }}
                       @endif

                   </td>
               </tr>

            @endforeach

            @endforeach


kosky2005 started a new conversation Loop Using Foreach In A Collection Where Contains • 6 months ago

I want to get records using foreach in view on collections only where contain 'transcode' or where transCode exist.

this is my collection

Collection {#519 ▼
  #items: array:19 [▼
    754924 => Collection {#500 ▼
      #items: array:4 [▼
        0 => {#441 ▼
          +"Staff_Number": "754924"
          +"opening_bal": "426.44"
        }
        1 => {#465 ▼
          +"Staff_Number": "754924"
          +"total": "390.00"
          +"transCode": "CONTRIBUTION"
        }
        2 => {#478 ▼
          +"Staff_Number": "754924"
          +"total": "136.44"
          +"transCode": "INTEREST"
        }
        3 => {#497 ▼
          +"Staff_Number": "754924"
          +"total": "-100.00"
          +"transCode": "PARTIAL WITHDRAWAL"
        }
      ]
    }
    754928 => Collection {#501 ▼
      #items: array:3 [▼
        0 => {#436 ▼
          +"Staff_Number": "754928"
          +"opening_bal": "311.81"
        }
        1 => {#464 ▼
          +"Staff_Number": "754928"
          +"total": "231.00"
          +"transCode": "CONTRIBUTION"
        }
        2 => {#479 ▼
          +"Staff_Number": "754928"
          +"total": "80.81"
          +"transCode": "INTEREST"
        }
      ]
    }
    754981 => Collection {#502 ▶}
    754989 => Collection {#503 ▶}
    754995 => Collection {#504 ▶}

so i will get something like

CONTRIBUTION: 390.00 INTEREST: 136.44 PARTIAL WITHDRAWAL: -100.00

so something like this

@foreach ($results->where contains as $row)

  {{ $row->transCode }}: {{ $row->total }}

@endforeach 

13th March, 2018

kosky2005 left a reply on Re Grouping Grouped Collections • 6 months ago

Any help pleas explain?

kosky2005 started a new conversation Re Grouping Grouped Collections • 6 months ago

I have this collection array

Collection {#520 ▼
  #items: array:19 [▼
    754924 => array:4 [▼
      0 => {#441 ▼
        +"Staff_Number": "754924"
        +"opening_bal": "426.44"
      }
      1 => {#465 ▼
        +"Staff_Number": "754924"
        +"total": "390.00"
        +"transCode": "CONTRIBUTION"
      }
      2 => {#478 ▼
        +"Staff_Number": "754924"
        +"total": "136.44"
        +"transCode": "INTEREST"
      }
      3 => {#497 ▼
        +"Staff_Number": "754924"
        +"total": "-100.00"
        +"transCode": "PARTIAL WITHDRAWAL"
      }
    ]
    754928 => array:3 [▶]
    754981 => array:3 [▶]
    754989 => array:3 [▶]
    754995 => array:3 [▶]

But i want this output

Collection {#520 ▼
  #items: array:19 [▼
    754924 => array:2 [▼
      0 => {#441 ▼
        +"Staff_Number": "754924"
        +"opening_bal": "426.44"
      }
      1 => {array:3 ▼
                  0 => {#476 ▼
                    +"Staff_Number": "754924"
                    +"total": "390.00"
                    +"transCode": "CONTRIBUTION"
                  }
                  1 => {#478 ▼
                    +"Staff_Number": "754924"
                    +"total": "136.44"
                    +"transCode": "INTEREST"
                  }
                  2 => {#497 ▼
                    +"Staff_Number": "754924"
                    +"total": "-100.00"
                    +"transCode": "PARTIAL WITHDRAWAL"
                  }
    ]
    754928 => array:2 [▶]
    754981 => array:2 [▶]
    754989 => array:2 [▶]
    754995 => array:2 [▶]
    755007 => array:2 [▶]

This is my code

 $getOpenBalTotal = DB::table('memcontribution')
            ->selectRaw('memcontribution.Staff_Number,sum(memcontribution.Amount) as opening_bal')
            ->leftJoin('memberslist','memberslist.staff_id', '=', 'memcontribution.Staff_Number')
            ->where('memberslist.department_id','=',$getDept)
            ->where('memcontribution.transDate','<',$getFromDate)
            ->groupBy('memcontribution.Staff_Number')
            ->get();


        $getOpenBalDetails = DB::table('memcontribution')
            ->selectRaw('memcontribution.Staff_Number,sum(memcontribution.Amount) as total,memcontribution.code as transCode')
            ->leftJoin('memberslist','memberslist.staff_id', '=', 'memcontribution.Staff_Number')
            ->where('memberslist.department_id','=',$getDept)
            ->where('memcontribution.transDate','<',$getFromDate)
            ->groupBy('memcontribution.Code')
            ->groupBy('memcontribution.Staff_Number')
            ->get();

         $collection = new Collection;

         $all = $collection->merge($getOpenBalTotal)->merge($getOpenBalDetails);

            $results = $all->groupBy('Staff_Number');


            $getAll = $results->map(function($item)
            {
                return $item->all();
            });

            dd($getAll);

19th February, 2018

kosky2005 left a reply on Get Position Subjects In Exams By Students Using Laravel • 7 months ago

Ok. So this is what i have been able to do so far

        $getScores = ViewResults::where('programmes', $getProgramme)
             ->where('ternYear',$getYear)
             ->where('termDesc',$getTerm)
             ->where('level',$getLevel)
            ->get()
            ->groupBy('subject')

            ->map(function($subject) {
                $rank = 0; $score = -1;
                return $subject->sortByDesc('exams100')->map(function($record) use (&$rank, &$score) {

                    if ($score != $record->getAttribute('exams100'))

                    {
                        $score = $record->getAttribute('exams100');
                        $rank++;
                    }

                    $record->setAttribute('Position', $rank);

                    return collect($record->getAttributes());
                });
            });

         $net = $getScores->collapse();

        $getResults = $net->all();

and i am getting this collection

array:71 [▼
  0 => Collection {#552 ▼
    #items: array:18 [▼
      "id" => 208
      "regNumber" => "Dash/15/16/A001"
      "fullName" => "AGBADZI DONKOR"
      "subject" => "English"
      "exams30" => 24.0
      "exams70" => 25.0
      "exams100" => 49.0
      "grade" => "C6"
      "remarks" => "Credit"
      "house" => "Unity"
      "programmes" => "Agriculture Science"
      "groups" => "Core"
      "ternYear" => "2016 / 2017"
      "termDesc" => "Second Term"
      "nextTerm" => "2017-05-04"
      "no_on_roll" => "10"
      "level" => "Two"
      "Position" => 1
    ]
  }
  1 => Collection {#551 ▼
    #items: array:18 [▼
      "id" => 210
      "regNumber" => "Dash/15/16/A002"
      "fullName" => "AMETEFE CHRISTIAN"
      "subject" => "English"
      "exams30" => 23.0
      "exams70" => 25.0
      "exams100" => 48.0
      "grade" => "C6"
      "remarks" => "Credit"
      "house" => "Justice"
      "programmes" => "Agriculture Science"
      "groups" => "Core"
      "ternYear" => "2016 / 2017"
      "termDesc" => "Second Term"
      "nextTerm" => "2017-05-04"
      "no_on_roll" => "10"
      "level" => "Two"
      "Position" => 2
    ]
  }
  2 => Collection {#550 ▶}
  3 => Collection {#549 ▶}
  4 => Collection {#548 ▶}

Now how do i get this form of collection

Collection {#416 ▼
  #items: array:71 [▼
    0 => {#414 ▼
      +"id": 208
      +"regNumber": "Dash/15/16/A001"
      +"fullName": "AGBADZI DONKOR"
      +"subject": "English"
      +"exams30": 24.0
      +"exams70": 25.0
      +"exams100": 49.0
      +"grade": "C6"
      +"remarks": "Credit"
      +"house": "Unity"
      +"programmes": "Agriculture Science"
      +"groups": "Core"
      +"ternYear": "2016 / 2017"
      +"termDesc": "Second Term"
      +"nextTerm": "2017-05-04"
      +"no_on_roll": "10"
      +"level": "Two"
      +"sregNumber": "Dash/15/16/A001"
      +"ranked": "1"
    }
    1 => {#415 ▼
      +"id": 197
      +"regNumber": "Dash/15/16/A001"
      +"fullName": "AGBADZI DONKOR"
      +"subject": "Mathematics"
      +"exams30": 23.0
      +"exams70": 35.0
      +"exams100": 58.0
      +"grade": "C4"
      +"remarks": "Credit"
      +"house": "Unity"
      +"programmes": "Agriculture Science"
      +"groups": "Core"
      +"ternYear": "2016 / 2017"
      +"termDesc": "Second Term"
      +"nextTerm": "2017-05-04"
      +"no_on_roll": "10"
      +"level": "Two"
      +"sregNumber": "Dash/15/16/A001"
      +"ranked": "1"
    }
    2 => {#407 ▶}
    3 => {#419 ▶}

17th February, 2018

kosky2005 left a reply on Get Position Subjects In Exams By Students Using Laravel • 7 months ago

Sorry that was typo error, I wanted to say position

kosky2005 left a reply on Get Position Subjects In Exams By Students Using Laravel • 7 months ago

Ok. Sorry for worrying you. but you are only help now to get to through this.

Collection {#23116 ▼
  #items: array:31 [▼
    "English" => Collection {#10418 ▶}
    "Mathematics" => Collection {#9123 ▶}
    "Intergrated Science" => Collection {#7836 ▶}
    "ICT" => Collection {#6731 ▶}
    "Social Studies" => Collection {#5431 ▶}
    "Physics" => Collection {#5207 ▶}
    "Animal Husbandry" => Collection {#5123 ▶}
    "General Agric" => Collection {#5038 ▶}
    "Chemistry" => Collection {#4814 ▶}
    "Economics" => Collection {#4407 ▶}
    "Financial Accounting" => Collection {#4268 ▶}
    "Cost Accounting" => Collection {#4155 ▶}
    "IBM" => Collection {#4019 ▶}
    "Elective Mathematics" => Collection {#3640 ▶}
    "Government" => Collection {#3023 ▶}
    "Geography" => Collection {#2817 ▶}
    "History" => Collection {#2772 ▶}
    "CRS" => Collection {#2322 ▶}
    "Literature in English" => Collection {#1871 ▶}
    "Akuapem Twi" => Collection {#1650 ▶}
    "Ewe" => Collection {#1519 ▶}
    "French" => Collection {#1458 ▶}
    "Biology" => Collection {#1188 ▶}
    "Textiles" => Collection {#1050 ▶}
    "Leather Work" => Collection {#978 ▶}
    "Graphics $ Design" => Collection {#839 ▶}
    "G.K.A" => Collection {#623 ▶}
    "Clothing & Textiles" => Collection {#620 ▶}
    "Management in Living" => Collection {#489 ▶}
    "Food and Nutrition" => Collection {#23115 ▶}
    "" => Collection {#23117 ▶}
  ]
}

i am getting this collection now. how to i i now find with the input parameters to get the desire results with the subjtech position.

kosky2005 left a reply on Get Position Subjects In Exams By Students Using Laravel • 7 months ago

i have and i am getting empty collection Collection {#11711 ▼ #items: [] }

This is when i added the input parameters.

    $getProgramme = Input::get('getProgramme');
    $getYear = Input::get('getYear');
    $getTerm = Input::get('getTerm');
    $getLevel = Input::get('getLevel');


    $results = ViewResults::all()
        ->groupBy('subject')
        ->map(function($subject) {
        $rank = 0; $score = -1;
        return $subject->sortByDesc('exams100')->map(function($record) use (&$rank, &$score) {
            if ($score != $record->getAttribute('exams100')) {
                $score = $record->getAttribute('exams100');
                $rank++;
            }

            $record->setAttribute('Position', $rank);

            return collect($record->getAttributes());
        });
    })
    ->where('programmes',$getProgramme)
    ->where('ternYear',$getYear)
    ->where('termDesc',$getTerm)
    ->where('level',$getLevel);
    //->get();


    dd($results);

kosky2005 left a reply on Get Position Subjects In Exams By Students Using Laravel • 7 months ago

Hello, Thank Alot. You have done great. I am in eloquent and laravel and trying to learn. This has gotten me stacked for about 2 days trying to find solution. i seems to follow your analysis but dont know how to complete it. I am not saving the data to DB, i want to return it to view. Can you you please complete it, so i can transfer the understanding to the actual work i am doing?

kosky2005 started a new conversation Get Position Subjects In Exams By Students Using Laravel • 7 months ago

I have a table called results with the following columns ID, Reg Number,Name, Subjects,Programmes,Year,Term,score. I want get positions of every subject by student where Programmes = Art and year = 2017 and Term = 1. I need help to achieve the below

ID Reg Number Name Subjects Programmes Year Term score Subject_Postion 1 1 Emma English Arts 2017 1 67 2 2 2 Frank English Arts 2017 1 90 1 3 3 Bright English Arts 2017 1 67 2 4 4 Mark English Arts 2017 1 88 3 5 1 Emma Maths Arts 2017 1 24 4 6 2 Frank Maths Arts 2017 1 78 1 7 3 Bright Maths Arts 2017 1 39 3 8 4 Mark Maths Arts 2017 1 67 2 9 1 Emma Science Arts 2017 1 24 3 10 2 Frank Science Arts 2017 1 68 2 11 3 Bright Science Arts 2017 1 68 2 12 4 Mark Science Arts 2017 1 80 1 13 1 Emma Orals Arts 2017 1 64 4 14 2 Frank Orals Arts 2017 1 77 3 15 3 Bright Orals Arts 2017 1 74 2 16 4 Mark Orals Arts 2017 1 90 1

The last column which is the Subject_Postion is what i want to achieve.

16th February, 2018

kosky2005 left a reply on Get Subject Name From Parent Query For Use In Subquery. • 7 months ago

Please, any help on how to deal with this issue I am stacked.

15th February, 2018

kosky2005 started a new conversation Get Subject Name From Parent Query For Use In Subquery. • 7 months ago

I have to get the subject name of every row for the query newsubject = " ". the query required 4 parameters and 3 have been provided by an input. The subject is to be obtained from the view row. i want to be able to obtained the rank to subject with a class of student with certain academic year and programme

$getProgramme = Input::get('getProgramme'); $getYear = Input::get('getYear'); $getTerm = Input::get('getTerm'); $getLevel = Input::get('getLevel');

$getResults = DB::table('resultsView')
    ->leftjoin(DB::raw('((SELECT sregNumber1, scorelevel1,term_Desc1,term_Year1, newsubject,prog1,
    CASE WHEN @prevRank = total_score1 THEN @curRank WHEN @prevRank := total_score1 THEN @curRank := @curRank + 1 END AS subject_ranked FROM scorebysubject q,
                      (SELECT @curRank :=0, @prevRank := NULL) r where prog1 ="' . $getProgramme . '" and  `scorelevel1` = "' . $getLevel . '" and term_Desc1 = "' . $getTerm . '"
                      and term_Year1 = "' . $getYear . '" and newsubject =  " " ORDER BY total_score1 Desc) as t3 )'), function ($join) {
        $join->on('sregNumber1', '=', 'regNumber')
            ->on('newsubject', '=', 'subject')
            ->on('term_Desc1', '=', 'termDesc')
            ->on('prog1', '=', 'programmes')
            ->on('term_Year1', '=', 'ternYear');
    })
    ->where('programmes', $getProgramme)
    ->where('ternYear', $getYear)
    ->where('termDesc', $getTerm)
    ->where('level', $getLevel)
    ->get();
Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.