Created
November 16, 2018 05:30
-
-
Save firecentaur/8b03b422fa8cc2bae393883e66627726 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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