fazlionline Posted May 31, 2009 Report Share Posted May 31, 2009 Hi all I have a database of some users, but serial number was missing in the output form. Now I want to add the serial number, but have problem. When I made the database, I made 4 test entries to check if it works or not, when that worked then I deleted those entries. Now when I use: echo "" . $row['id'] . ""; It works properly, but it starts form 5 and so on. And I want it to start form 1. I also want my database to be ordered by names. $result = mysql_query("SELECT * FROM my_table ORDER BY id") or die(mysql_error()); Any suggestion! Thanks Quote Link to comment Share on other sites More sharing options...
fazlionline Posted May 31, 2009 Author Report Share Posted May 31, 2009 I just need a code to RESET my id AUTO INCREMENT Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted May 31, 2009 Report Share Posted May 31, 2009 I suggest you "DROP" the database and start with a new install. The auto-increment primary key does not need to start at one. That is a human consideration. The Database only needs a unique value. And to answer your next concern, the index key does not need to be consecutive. If you delete a key, the DB will know about it and handle the list properly. Quote Link to comment Share on other sites More sharing options...
fazlionline Posted June 1, 2009 Author Report Share Posted June 1, 2009 I suggest you "DROP" the database and start with a new install. but i have users in that table, what should i do with them? Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted June 1, 2009 Report Share Posted June 1, 2009 Simply let the Database management system handle the 'keys'. They do not need to be starting at '1' or they do not need to be consecutive. The DBMS will handle them just fine with missing elements. Quote Link to comment Share on other sites More sharing options...
fazlionline Posted June 2, 2009 Author Report Share Posted June 2, 2009 Simply let the Database management system handle the 'keys'. OK, but how can i let the database management sysem to handle the 'keys'? Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted June 2, 2009 Report Share Posted June 2, 2009 It does it all by itself. Quote Link to comment Share on other sites More sharing options...
fazlionline Posted June 3, 2009 Author Report Share Posted June 3, 2009 (edited) hi all i did it, with another code see the red code, i added : <?php // Make a MySQL Connection // Get all the data from the "example" table $result = mysql_query("SELECT * FROM schooldb ORDER BY regname") or die(mysql_error()); echo " echo " S Name DoB Domicile Phone Country City Position Organization Profession Education Email "; $ctr = 1; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array($result)) { echo " echo "" . $ctr . ""; echo "" . $row['regname'] . ""; echo "" . $row['regdob'] . ""; echo "" . $row['regdomi'] . ""; echo "" . $row['regmob'] . ""; echo "" . $row['regcountry'] . ""; echo "" . $row['regcity'] . ""; echo "" . $row['regposition'] . ""; echo "" . $row['regorg'] . ""; echo "" . $row['regpro'] . ""; echo "" . $row['regedu'] . ""; echo "" . $row['regemail'] . ""; echo "";$ctr++; } echo "";?> Edited June 3, 2009 by fazlionline Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.