WHERE commentGroup='{$childGroup}' AND gOrder > '{$childOrder}' + 1 AND status=1
";
$this->update($sql);
}
else{//부모에게 자식이 없을 때
$sql="
INSERT INTO tblComment(userFk, targetFk, commentGroup, gOrder, depth, content, commentType)
VALUES
(
'{$userFk}',
'{$targetFk}',
IFNULL(SELECT commentGroup FROM tblComment WHERE commentType='{$commentType}' AND commentGroup='{$parentGroup}' AND depth=0, '{$this->mysql_insert_id()}'),
IFNULL(SELECT gOrder FROM tblComment WHERE commentType='{$commentType}' AND commentGroup='{$parentGroup}', -1)+1,
IFNULL(SELECT depth FROM tblComment WHERE commentType='{$commentType}' AND commentGroup='{$parentGroup}', -1)+1,
(SELECT commentGroup FROM tblComment WHERE commentNo='{$parentNo}' AND status=1), //부모의 그룹
(SELECT gOrder + 1 FROM tblComment WHERE commentNo='{$parentNo}' AND status=1), //부모 순서+1
(SELECT depth + 1 FROM tblComment WHERE commentNo='{$parentNo}' AND status=1), //부모 깊이+1
'{$content}',
'{$commentType}'
'{$commentType}',
1,
NOW()
)
";
$this->update($sql);
$sql="
UPDATE tblComment
SET gOrder=gOrder+1
WHERE commentGroup=(SELECT commentGroup FROM tblComment WHERE commentNo='{$parentNo}' AND status=1) AND gOrder > (SELECT gOrder + 1 FROM tblComment WHERE commentNo='{$parentNo}' AND status=1) AND status=1