Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP删除行时更新mySQL数据库中的ID_Php_Mysql_Indexing - Fatal编程技术网

使用PHP删除行时更新mySQL数据库中的ID

使用PHP删除行时更新mySQL数据库中的ID,php,mysql,indexing,Php,Mysql,Indexing,我有一个数据表,有3列:索引、标题、消息。例如: 1 'Title1' 'Hi!' 2 'Title2' 'Sup' 3 'Title3' 'Nothing' 如果我删除例如中间的一个,索引编号将包含一个间隙。如何更新它们以修复此问题?有没有mysql的偏好?(我真的需要它们井然有序,没有间隙)您可以使用一个自动的按钮自动完成此操作 没关系,我没有想到最简单的:id=id-1,其中id大于删除的id。对不起! CREATE TRIGGER update_in

我有一个数据表,有3列:索引、标题、消息。例如:

1    'Title1'    'Hi!'
2    'Title2'    'Sup'
3    'Title3'    'Nothing'

如果我删除例如中间的一个,索引编号将包含一个间隙。如何更新它们以修复此问题?有没有mysql的偏好?(我真的需要它们井然有序,没有间隙)

您可以使用一个自动的按钮自动完成此操作


没关系,我没有想到最简单的:id=id-1,其中id大于删除的id。对不起!
CREATE TRIGGER update_indexes AFTER DELETE on your_table
FOR EACH ROW
BEGIN
    UPDATE
        your_table
    SET
        your_table.`index` = your_table.`index` - 1
    WHERE your_table.`index` > old.`index`;
END