Learn, Share, Build

207
October 13, 2017, at 7:16 PM

Its an online result marker. Once the user clicks save it gets the CA(Continious assessment) and it gets the Exam marks and the teachers remark for the particular student. I want to know how i can insert these fields into my database the right way.

return $request->all();

the above code returns the image below

Answer 1
$i = 0;
foreach($request->id as $id) {
    $model = new Model;
    $model->user_id = $id;
    $model->ca_mark = $request->ca_mark[$i];
    $model->exam_mark = $request->ca_mark[$i];
    $model->remarks = $request->remarks[$i];
    $model->save();
    $i++;
}

Query Builder

$i = 0;
foreach($request->id as $id) {
    DB::table('table')->insert([
        'user_id' => $id, 
        'ca_mark' => $request->ca_mark[$i],
        'exam_mark' => $request->ca_mark[$i],
        'remarks' => $request->remarks[$i]
    ]);
    $i++;
}

The above code has been written based on an assumption of the database table structure. In short, foreach on the ID's as this would be the student ID, and take the ca_mark, exam_mark and remark based on the key of the id.

Rent Charter Buses Company
READ ALSO
Learn, Share, Build

Learn, Share, Build

I am trying to make simple MySQL query to display upcoming birthdays using below queryHow to exclude/remove previous(yesterday) day from showing

212
Learn, Share, Build

Learn, Share, Build

I have to port some DBS into stand alone MySQL Version: 50

234
Learn, Share, Build

Learn, Share, Build

I have a function is MySql which calculates the number of working dates between two given dates but I would like to know the logic that is being used in itThe sql function is as follows:

253