Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
Iam want to get sum of degree for each row with json

Hello I have a problem with PHP laravel with JSON I am saving in filled

  • JSON data name is element_degree
  • The key is the element and the value is the degree

Problem I want show user data and get sum of degree for each user how can I do this ?

This is my data:

Id User Month Element_degree
13 2 2 "{"13":"122","14":"130"}"
14 3 2 "{"13":"100","14":"120"}"
15 4 2 "{"13":"140","14":"100"}"

And this is my code in controller:

$data=empdata::all()

How can I get a sum of degrees for each row from field element_degree for each user ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

try this code it will add element_degree_total field in your emp data for each data

$employees = empdata::all();
    foreach($employees as $employee){
        $data = json_decode($employee->element_degree);
        $total = 0;
        foreach ($data as $d) {
             $total += $d;
        }
        $employee->element_degree_total = $total;
    }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!