sql - Convert PHP Query to Laravel in Controller -
can convert php code in laravel.
$result = mysqli_query($conn, "select birthday, count(*) person group birthday;"); while ($row = mysqli_fetch_array($result, mysql_num)) { $yearvalues[$row[0]] = (int)$row[1]; }
like this:
$female = enroll::select(db::raw("sum(tot_enroll) count")) ->orderby(db::raw('sy')) ->groupby(db::raw("(sy)")) ->where('gender','=', 'female') ->get()->toarray(); $female = array_column($female, 'count');
it's simple,
you can convert sql query query builder in laravel this:
db::table('person')->select('birthday',db::raw('count(*) count')) ->groupby('birthday') ->get();
in case, have forgot select sy
, gender
orderby
, groupby
, where
nothing try code data.
db::table('enrollments')->select(db::raw('sy','gender','sum(tot_enroll) count')) ->where('gender','=', 'female') ->groupby('sy') ->orderby('sy') ->get(); ->toarray();
Comments
Post a Comment