-1

タイトルにあるように、このクエリの何が問題なのかわかりません。

$query = "UPDATE ".$SupportFaqTable." a
            INNER JOIN ".$SupportRateFaqTable." b 
              ON b.faq_id=a.id
            SET 
               a.rate=CASE WHEN b.updated='1' THEN ROUND(((a.num_rate * a.rate - b.rate) + ?)/(a.num_rate),2) ELSE ROUND(((a.rate + ?)/(a.num_rate+1),2) END,
               a.num_rate=CASE WHEN b.updated='1' THEN a.num_rate ELSE a.num_rate+1 END,
               b.updated='0'
            WHERE  a.id=?";

これは$query次のとおりです。

UPDATE razorphyn_support_faq a
INNER JOIN razorphyn_support_faq_rate b 
    ON b.faq_id=a.id
SET 
    a.rate=CASE WHEN b.updated='1' THEN ROUND(((a.num_rate * a.rate - b.rate) + ?)/(a.num_rate),2) ELSE ROUND(((a.rate + ?)/(a.num_rate+1),2) END,
    a.num_rate=CASE WHEN b.updated='1' THEN a.num_rate ELSE a.num_rate+1 END,
    b.updated='0'
WHERE  a.id=?

EDIT
明示的なエラー:

["You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE  a.id=?' at line 8"]

編集
これは完全なphp関数です:

$rate=(is_numeric($_POST['rate']))? $_POST['rate']:0;
$GT86=(is_numeric($_POST['idBox']))? $_POST['idBox']/3823:0;
if($GT86>10 && $rate>0){
    $mysqli = new mysqli($Hostname, $Username, $Password, $DatabaseName);
    $stmt = $mysqli->stmt_init();
        $query = "INSERT INTO ".$SupportRateFaqTable." (`faq_id`,`usr_id`,`rate`) VALUES (?,?,?) ON DUPLICATE KEY UPDATE `rate`=?,`updated`='1'";
        $stmt->prepare($query)
            $stmt->bind_param('iiii',$GT86,$_SESSION['id'],$rate,$rate)
                $stmt->execute()
                    $query = "UPDATE ".$SupportFaqTable." a
                                INNER JOIN ".$SupportRateFaqTable." b 
                                    ON b.faq_id=a.id
                                SET 
                                    a.rate=CASE WHEN b.updated='1' THEN ROUND(((a.num_rate * a.rate - b.rate) + ?)/(a.num_rate),2) ELSE ROUND(((a.rate + ?)/(a.num_rate+1),2) END,
                                    a.num_rate=CASE WHEN b.updated='1' THEN a.num_rate ELSE a.num_rate+1 END,
                                    b.updated='0'
                                WHERE  a.id=?";
                    $stmt->prepare($query)
                        $stmt->bind_param('iii', $rate,$rate,$GT86)
                            $stmt->execute()
                                echo json_encode(array(0=>'Voted'));
}
else
    echo json_encode(array(0=>'Invalid Information'));
exit();

これらはテーブルです:

CREATE TABLE IF NOT EXISTS `razorphyn_support_faq` (
`id`                INT(5)          UNSIGNED        NOT NULL AUTO_INCREMENT,
`question`          VARCHAR(200)                    NOT NULL,
`answer`            VARCHAR(2000)                   NOT NULL,
`position`          INT(4)          UNSIGNED        NOT NULL    DEFAULT 0,
`active`            ENUM('0','1')                   NOT NULL    DEFAULT '1',
`num_rate`          INT(8)          UNSIGNED        NOT NULL    DEFAULT 0,
`rate`              DECIMAL(4,2)    UNSIGNED        NOT NULL    DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY(`question`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=15;

CREATE TABLE IF NOT EXISTS `razorphyn_support_faq_rate`(
`id`                BIGINT(15)      UNSIGNED        NOT NULL AUTO_INCREMENT,
`faq_id`            INT(5)          UNSIGNED        NOT NULL,
`usr_id`            BIGINT(15)      UNSIGNED        NOT NULL,
`rate`              DECIMAL(4,2)    UNSIGNED        NOT NULL    DEFAULT 0,
`updated`           ENUM('0','1')                   NOT NULL    DEFAULT '0',
`note`              VARCHAR(200)                    ,
PRIMARY KEY (`id`),
UNIQUE KEY(`faq_id`,`usr_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=15;
4

1 に答える 1