1

Suppose i have a database that store report from employees which first column is reportID(auto increment), staffID,name,department and so on.

Everytime i submit i report from my php page it will display increment number (reportID) in my php page. So lets say i got 3 report ID stored in the table, i want to delete three record, and then add 1 new record to the table, but now the reportID display as 4 because the past three reportID are 1,2,3, so how do i reset the new record to 1 instead of 4? is there a code to reset it? This is my deletereport.php

<?php
include('adminconfig.php');
include('config.php');

$reportID = mysql_real_escape_string($_GET['id']);

$sql="DELETE FROM `report` WHERE `reportID`='$reportID'";
$result=mysql_query($sql);

if(!$result){
   die('invalid query:'.mysql_error());
 }
 else
 ?>
<p style="font-family:arial;color:#0066CC;font-size:30px;">One row deleted...</p>
<?php
header('Refresh:3; url=viewreportdb.php');
die;

?>
4

3 回答 3

2

您必须截断表以重置自动递增的值或只是

ALTER TABLE yourtable AUTO_INCREMENT = 1
于 2013-08-22T01:56:23.770 回答
1

类似的讨论在这里

MySQL中删除后自动增量

可能不想重置,只使用自动增量。

于 2013-08-22T01:56:50.883 回答
0

query following from PHP:

ALTER TABLE tablename AUTO_INCREMENT = 1
于 2013-08-22T01:55:35.237 回答