I defined a function in my navigation model that executes the request, and I was wondering if there is a way to generate / execute the "Zendy" request. The query I used was suggested by Bill Karwin in another here to set a random recording order. I tried using a prepared statement, but the values ββin the SIGN () function were quoted.
I am using a PDO adapter for MySQL.
/**
*
*/
public function setPosition($parentId, $oldPosition, $newPosition)
{
$parentId = intval($parentId);
$oldPosition = intval($oldPosition);
$newPosition = intval($newPosition);
$this->getAdapter()->query("
UPDATE `navigation`
SET `position` = CASE `position`
WHEN $oldPosition THEN $newPosition
ELSE `position` + SIGN($oldPosition - $newPosition)
END
WHERE `parent_id` = $parentId
AND `position` BETWEEN LEAST($oldPosition, $newPosition)
AND GREATEST($oldPosition, $newPosition)
");
return $this;
}
source
share