I have a Student table and StudNo field which is set as primary key and auto increment is enabled. My problem is when I delete a specific row I noticed that the auto increment value remains the same. Also I deleted all the rows but the auto increment value is still 45. So is there a way to get the current auto increment value and store it to a variable? Sample code is much appreciated. Thanks

    If you want to delete all the rows and start at 1 again, use the TRUNCATE TABLE command.

    Other than that for fresh re-starts, does it really matter if they are sequentially numbered?

      Yes I need it sequentially and I manage to got it working heres my sample code

      $tablename = "Student";
      $auto_increment = 0;
      $qShowStatus = "SHOW TABLE STATUS LIKE '$tablename'";
      $qShowStatusResult = mysql_query($qShowStatus) or die ( "Query failed: " . mysql_error() . "<br/>" . $qShowStatus );
      
      $row = mysql_fetch_assoc($qShowStatusResult);
      $auto_increment = $row['Auto_increment'];
      
      echo "auto increment value: $auto_increment";

      I will marked it as resolved
      Thanks for your reply sir🙂

        Curious. Would anyone please explain to me why that might matter?

          Write a Reply...