Skip to content

Instantly share code, notes, and snippets.

@firecentaur
Created November 16, 2018 05:30
Show Gist options
  • Save firecentaur/8b03b422fa8cc2bae393883e66627726 to your computer and use it in GitHub Desktop.
Save firecentaur/8b03b422fa8cc2bae393883e66627726 to your computer and use it in GitHub Desktop.
public function testMultipleChange1(){
$video1 = $this->testCase->createTestVideo(9, 'Group');
$video2 = $this->testCase->createTestVideo(9, 'Group');
$video3 = $this->testCase->createTestVideo(9, 'Group');
$multipleUpdate = 'UPDATE video SET order = CASE id ';
$arr=[];
$arr[]=$video1;
$arr[]=$video2;
$arr[]=$video3;
$idsStr='';
foreach($arr as $index => $eachVideo){
$multipleUpdate .=" WHEN '".$eachVideo->id."' THEN '".$index."' ";
$id = $eachVideo->id;
$idsStr.="'$id',";
}
if (substr($idsStr, -1, 1) == ',')
{
$idsStr = substr($idsStr, 0, -1);
}
$multipleUpdate .= "END";
$multipleUpdate .= "WHERE id IN($idsStr);";
$multipleUpdate='';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment