0

好的,所以我有这个脚本,它可以更新或将值插入 mysql,还可以自动增加一列并将枚举值从 0 设置为 1。

现在我试图弄清楚我可能会如何反转它,以便将枚举值设置回 0(我认为我知道该怎么做)我还需要弄清楚我可以如何递减或与递增相反的任何内容,是否可以在自动增量列中为 -1?

只要我可以减少自动增量列并将枚举值从 1 更改为 0,就不一定需要删除这些值。

谁能告诉我我该怎么做?谢谢。

<?php

    require_once('includes/session.php');
    require_once('includes/functions.php');
    require('includes/_config/connection.php');

    session_start();

        confirm_logged_in();

        if (isset ($_GET['to'])) {
        $user_to_id = $_GET['to'];


    }


    if (!isset($_GET['to']))
        exit('No user specified.');

    $user_id = $_GET['to'];


    $result = mysql_query("SELECT * FROM ptb_likes WHERE liked_id ='".$user_to_id."' ");

    if( mysql_num_rows($result) > 0) {
    mysql_query("UPDATE ptb_likes SET likes = likes +1 WHERE liked_id = '".$user_to_id."' ");


        $user_to_id = mysql_query("ALTER TABLE likes AUTO_INCREMENT = $id");
    }
    else
    {
        mysql_query("INSERT INTO ptb_likes (user_id, liked_id) VALUES (".$_SESSION['user_id'].", ".$user_to_id.")"); 

    }



    if($result) 
    { 
    mysql_query("UPDATE ptb_likes SET user_id_has_liked='1' WHERE user_id=".$_SESSION['user_id']."") 
    or die(mysql_error());

    header("Location: {$_SERVER['HTTP_REFERER']}");

    }
    ?>
4

1 回答 1

0

正如其他地方所建议的那样

create table b
(
id int not null auto_increment primary key,
foo boolean not null
);

 insert into b (foo) values (true), (false), (false),  (true), (true);

update b set
foo = not foo;
于 2013-02-10T08:50:06.443 回答