mercredi 19 décembre 2018

Reduce time for update query in Laravel (without for loop, for same key and multiple values)

for ($i = 0; $i < count($ids); $i++) {
            ls_player_details::where('Bib_no', $ids[$i])
                ->update(['chestno' => $chestnos[$i]]);
        }

This update query takes 8secs for 162 records, so want to reduce the time

so i made this one;

 for ($i = 0; $i < count($chestnos); $i++) {
        $data[]=array(
            'chestno'=> $chestnos[$i]
        );
    }

    ls_player_details::whereIn('Bib_no',$ids)->update($data);

now what's the problem is;

now i getting data like this

[ 
    {
    "chestno": 50
    },
    {
        "chestno": 51
    },
    {
        "chestno": 52
    },
    {
        "chestno": 53
    },
    {
        "chestno": 54
    },
    {
        "chestno": 55
    },

]

but i want to get array like;

["chestno": 50,"chestno": 50,"chestno": 50]

problem:

pushing multiple values for same key in to array using for loop

and i want to know there is any other method to done the same thing



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire