Topic: How to turn back the index counter (auto_increment)
I made these scripts and runs well! But my problem is when I Deleted the last records that is greater than 5, the number or counter still continue to increment instead of following the last number in the id field.
I mean like this:

I used this code:
<html>
<head></head>
<body>
<form method = "post">
Country: <input type = "text" name = "country"><br><br>
Animal: <input type = "text" name = "animal"><br><br>
<input type = "submit" name = "submit">
</form>
<?php
if (isset($_POST['submit']))
{
$country = $_POST['country'];
$animal = $_POST['animal'];
$db = 'testdb';
$connection = mysql_connect('localhost','root','test');
mysql_select_db($db);
mysql_query("INSERT INTO symbols (country, animal) VALUES('$country', '$animal')");
$query = "SELECT * FROM symbols ORDER BY id";
$result = mysql_query($query);
if (mysql_num_rows($result) >0)
{
echo "<table border = 1 cellpadding = 5>";
while ($row = mysql_fetch_row($result))
{
echo "<tr>";
echo "<td>" .$row[0]. "</td>";
echo "<td>" .$row[1]. "</td>";
echo "<td>" .$row[2]. "</td>";
echo "</tr>";
}
echo "</table>";
}
echo "<br>";
echo mysql_num_rows($result) . " Total No. of Records";
mysql_free_result($result);
mysql_close($connection);
}
?>
</body>
</html>
Thanks in advanced! ![]()
Last edited by madmhan84 (August 19, 2009 10:42 pm)

