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;

?>
nickee89
  • 69
  • 3
  • 8

3 Answers3

2

You have to truncate the table to reset auto incremented values or just

ALTER TABLE yourtable AUTO_INCREMENT = 1
Tushar Gupta
  • 15,504
  • 1
  • 29
  • 47
1

similar discussion here

Auto Increment after delete in MySQL

Probably don't want to reset and just use auto-increment.

Community
  • 1
  • 1
djbrick
  • 213
  • 1
  • 4
0

query following from PHP:

ALTER TABLE tablename AUTO_INCREMENT = 1
Sujit Poudel
  • 541
  • 7
  • 19