vendredi 24 novembre 2017

How to generate a query to db if several “where” and “update” are added in the loop?

I have a method with four incoming arrays. The first two arrays $whereColumns[] and $updateColumns[] contain columns names. The third column $whereFilters[] contains filters for "where" methods. And the last one $updateFilters[] contains values for updating. How can I generate only one search query with several "where" methods and several updated columns? Now I know only how create a query with several "where" methods in a loop.

for($i=0; $<count($whereColumns); $i++){
    $query->where($whereColumns[$i], '=', $whereFilters[$i]);
}
$result = $query->get();

But how to generate a query with "update" like this (but this doesn't work):

for($i=0; $i<count($updateColumns); $i++){
    $query->update($updateColumns[$i] => $updateFilters[$i]); 
} 
$result = $query->get();

Both of these loops should generate one search query in total for updating a table data.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire