我想在删除mysql记录时执行查询,以便重新排序ID自动增量。
//删除记录:
if(isset($_REQUEST['id']) && $_REQUEST['id']<>'')
{
$delete=mysql_query("delete from planning where id='".$_REQUEST['id']."'");
echo "<script type=\"text/javascript\">".
"alert('delete ok');".
"</script>";
}
$msg='';
if(isset($_REQUEST['msg']))
{
$msg=$_REQUEST['msg'];
}
if(isset($_REQUEST['delete']) && $_REQUEST['delete']<>'' && $_REQUEST['delete'] == 'true')
{
$planning_id = $_REQUEST['id'];
$query = "delete from planning where id = '".$planning_id."' " ; ;
$output=mysql_query($query);
}
我无法执行但使用phpmyadmin的mysql查询:
ALTER TABLE `planning` DROP `id`;
ALTER TABLE `planning` AUTO_INCREMENT = 1;
ALTER TABLE `planning` ADD `id` int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;
任何有想法的人都可以吗?
提前致以最热烈的感谢!
答案 0 :(得分:1)
考虑更改primary key system。
此外,您的代码易受SQL注入攻击。切换到prepared statements
$counter = array();
foreach($array as $value) {
$keyName = str_replace(' ','',$value["size"]);
if (!array_key_exists($counter,$keyName) array[$keyName] = $value["count"];
else array[$keyName] += $value["count"];
}
函数调用集合也是deprecated,因此更有理由进行切换。