php mysqli多查询重新排序自动增量ID

时间:2014-05-23 03:00:40

标签: php mysql sql mysqli auto-increment

嗨所以我第一次使用mysqli多查询。我在phpmyadmin中尝试了这个查询并且它可以工作,但是在运行此查询时我得到以下错误。

if(isset($_GET['del'])){

    $delete_id = $_GET['del'];

    $delete_query = "DELETE FROM `gallerycontent` WHERE `pic_id` = '$delete_id';";
    $delete_query. = "SET @num = 0;";
    $delete_query. = "UPDATE `gallerycontent` SET `pic_id` = @num := (@num+1);";
    $delete_query. = "ALTER TABLE `gallerycontent` AUTO_INCREMENT =1;";

    if(mysqli_multi_query($link, $delete_query)){
        echo "<script>alert('The image has been deleted')</script>";
        echo "<script>window.open('reviewgallery.php','_self')</script>";
    }
}

这是我得到的错误

Parse error: syntax error, unexpected '=' in C:\wamp\www\mysqli\deleteimage.php on line 13

这是

$delete_query. = "SET @num = 0;";

也适用于其他变种。

不确定答案是什么,而且我无法在这个问题上找到太多帮助。感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您的串联运算符不正确:它应该是.=而不是. =

$delete_query = "DELETE FROM `gallerycontent` WHERE `pic_id` = '$delete_id';";
$delete_query .= "SET @num = 0;";
$delete_query .= "UPDATE `gallerycontent` SET `pic_id` = @num := (@num+1);";
$delete_query .= "ALTER TABLE `gallerycontent` AUTO_INCREMENT =1;";