删除某些值时,我需要选择哪些设置来维护有序队列。我创建带有自动增量和主键的 id 表。当我第一次插入值时没关系。就像1,2,3,4,5...
删除某些值时,顺序会发生变化1,5,3...
。而且脚本效果不好。
一些代码:
if(isset($submit)){
if($pav2 == ""){
header('Location: index.php');
}
else {
$select = mysql_query("SELECT new_id from naujiena ORDER by new_id");
$zym = mysql_num_rows($select);
if($zym == 0) {
$query = mysql_query("INSERT INTO naujiena (new_id,new_pav) VALUES ('1','$pav2')");
header('Location: index.php');
}
else {
$select2 = mysql_query("SELECT new_id from naujiena ORDER BY new_id DESC LIMIT 1");
$max_public_id = mysql_fetch_row($select2);
$query2 = mysql_query("INSERT INTO naujiena (new_id,new_pav) VALUES ('$max_public_id[0]'+1,'$pav2')");
header('Location: index.php');
}
}
}
当 new_pav 和 new_id 刚刚添加时: 示例:
new_id new_pav
5 some_value
4 some_value
3 some_value
2 some_value
1 some_value
当我删除某些内容时,它变成:例如:
new_id new_pav
4 some_value
2 some_value
3 some_value
1 some_value