Sunday, May 20, 2018

Convert row data into column data using Laravel - development

Convert row data into column data using Laravel

Hello I am facing a problem. I am trying at my best to solve this but can not. I am trying to do this I have three table which is illustrated below image. I want to Output like last table in the given image

And this is my laravel code——————

$academic_year=$request->academic_year;
        $class=$request->class_name;
        $medium=$request->medium;
        $section=$request->section_name;        
        $exam_name=$request->exam_name;

        $subject_list=DB::table('tbl_subject')                    
                    ->where('class_name', 'LIKE', "%$class%")                                       
                    ->get();     


$student_all_subject_mark_search_result=DB::table('tbl_student_subject_mark') 
            ->join('tbl_student_admission', 'tbl_student_subject_mark.student_registration_id', '=', 'tbl_student_admission.student_registration_id')
            ->select('tbl_student_subject_mark.*', 'tbl_student_admission.student_registration_id',  'tbl_student_admission.student_full_name_english', 'tbl_student_admission.class', 'tbl_student_admission.medium', 'tbl_student_admission.section', 'tbl_student_admission.roll_no',
            'max(if(subject_name = "Bangla 1st Paper" , total_obtained_mark, null)) A',
            'max(if(subject_name = "Bangla 2nd Paper" , total_obtained_mark, null)) B',
            'max(if(subject_name = "English 1st Paper" , total_obtained_mark, null)) C',
            'max(if(subject_name = "English 2nd Paper" , total_obtained_mark, null)) D',
            'max(if(subject_name = "Mathematics" , total_obtained_mark, null)) E',
            'max(if(subject_name = "Religion" , total_obtained_mark, null)) F')
            ->where('tbl_student_subject_mark.academic_year', $academic_year)
            ->where('tbl_student_admission.class', $class)
            ->where('tbl_student_admission.medium', $medium)
            ->where('tbl_student_admission.section', $section)                
            ->where('tbl_student_subject_mark.exam_title', $exam_name)
            ->where('tbl_student_admission.student_registration_id is not null')
            ->groupBy('tbl_student_subject_mark.student_registration_id')                
            ->get();

But It shows an error

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'max(if(subject_name 
= "Bangla 1st Paper" , total_obtained_mark, null)) A' in 'field list' (SQL: 
select `tbl_student_subject_mark`.*, 
`tbl_student_admission`.`student_registration_id`, ..................



from Laravel Questions and Answers https://laravelquestions.com/laravel/convert-row-data-into-column-data-using-laravel/
via Lzo Media

No comments:

Post a Comment