shebbycs Posted April 6, 2013 Share Posted April 6, 2013 This my id format bigint and auto increment For example I want to call from database how can i make the ID number start from 1 and finish according to number of available data? Quote Link to comment https://forums.phpfreaks.com/topic/276603-take-the-autoincrement-id-from-database-and-call-as-default-number/ Share on other sites More sharing options...
trq Posted April 6, 2013 Share Posted April 6, 2013 Pardon? Quote Link to comment https://forums.phpfreaks.com/topic/276603-take-the-autoincrement-id-from-database-and-call-as-default-number/#findComment-1423242 Share on other sites More sharing options...
shebbycs Posted April 6, 2013 Author Share Posted April 6, 2013 (edited) Pardon? The picture show one of my field that is ID(Auto Increment) Format(BIGINT) My main question is if I want to retrieve the ID as it was from database, I want the ID to be arrange from first number because the number was 116,117 and 118 and I want it start from 1 Edited April 6, 2013 by shebbycs Quote Link to comment https://forums.phpfreaks.com/topic/276603-take-the-autoincrement-id-from-database-and-call-as-default-number/#findComment-1423246 Share on other sites More sharing options...
trq Posted April 6, 2013 Share Posted April 6, 2013 My main question is if I want to retrieve the ID as it was from database, I want the ID to be arrange from first number because the number was 116,117 and 118 and I want it start from 1 That is not a question. Quote Link to comment https://forums.phpfreaks.com/topic/276603-take-the-autoincrement-id-from-database-and-call-as-default-number/#findComment-1423254 Share on other sites More sharing options...
l0gic Posted April 6, 2013 Share Posted April 6, 2013 I have to say it: $id = $id-115; Enjoy.. Everyone, enjoy. Quote Link to comment https://forums.phpfreaks.com/topic/276603-take-the-autoincrement-id-from-database-and-call-as-default-number/#findComment-1423258 Share on other sites More sharing options...
Jessica Posted April 6, 2013 Share Posted April 6, 2013 You shouldn't change the ID. Quote Link to comment https://forums.phpfreaks.com/topic/276603-take-the-autoincrement-id-from-database-and-call-as-default-number/#findComment-1423285 Share on other sites More sharing options...
jcbones Posted April 6, 2013 Share Posted April 6, 2013 I'm with Jessica on this one. If you find the need to change the ID, then your design needs work. There is no reason to change the ID, as then you can/will corrupt the data protocols, especially if that table is tied to other tables through the PRIMARY KEY. Quote Link to comment https://forums.phpfreaks.com/topic/276603-take-the-autoincrement-id-from-database-and-call-as-default-number/#findComment-1423295 Share on other sites More sharing options...
gizmola Posted April 6, 2013 Share Posted April 6, 2013 I'm guessing that the question is: how do you reset the auto_increment id for a table back to 1? This will only work if all the rows are removed from the table, either with DELETE or TRUNCATE table. ALTER TABLE yourtable AUTO_INCREMENT = 1; To accomplish this with renumbering, you can select into a temp table and then reinsert, omitting the old id column.CREATE TABLE t_yourtable AS SELECT * FROM yourtable; TRUNCATE TABLE yourtable; ALTER TABLE yourtable AUTO_INCREMENT = 1; INSERT INTO yourtable (col2, col3... etc) SELECT col2, col3... etc FROM t_yourtable; *Note* I think that truncate table may set the auto_increment back to 1, but test it with our version just to be sure. Quote Link to comment https://forums.phpfreaks.com/topic/276603-take-the-autoincrement-id-from-database-and-call-as-default-number/#findComment-1423314 Share on other sites More sharing options...
trq Posted April 6, 2013 Share Posted April 6, 2013 I'm guessing that the question is: how do you reset the auto_increment id for a table back to 1?Why guess? I'm trying to get the op to ask a decent question. This thread is a joke. Quote Link to comment https://forums.phpfreaks.com/topic/276603-take-the-autoincrement-id-from-database-and-call-as-default-number/#findComment-1423321 Share on other sites More sharing options...
gizmola Posted April 8, 2013 Share Posted April 8, 2013 Why guess? I'm trying to get the op to ask a decent question. This thread is a joke.Good point Tony. Quote Link to comment https://forums.phpfreaks.com/topic/276603-take-the-autoincrement-id-from-database-and-call-as-default-number/#findComment-1423554 Share on other sites More sharing options...
shebbycs Posted April 9, 2013 Author Share Posted April 9, 2013 Why guess? I'm trying to get the op to ask a decent question. This thread is a joke. Sincerely my english so bad and I am not very fluent in english Quote Link to comment https://forums.phpfreaks.com/topic/276603-take-the-autoincrement-id-from-database-and-call-as-default-number/#findComment-1423619 Share on other sites More sharing options...
shebbycs Posted April 9, 2013 Author Share Posted April 9, 2013 (edited) trq and gizmola sir let me describe in detail based on below picture This is my field and the branch_codename is location and I had 23 location and for testing I just put 2 location only Let say if the ID number from table above was arrange from 1 so there will be 1 -5 number and my search query will be where branch_codename='TK02' for sure it will return ID number 2 and 4 My main question was if I call the location and using html table I want the number sorting back to 1 and 2 instead of 2 and 4 How to do that please Edited April 9, 2013 by shebbycs Quote Link to comment https://forums.phpfreaks.com/topic/276603-take-the-autoincrement-id-from-database-and-call-as-default-number/#findComment-1423621 Share on other sites More sharing options...
gizmola Posted April 10, 2013 Share Posted April 10, 2013 You need to do that in your procedural code. When you get the result set, you can use a variable and as you fetch each row you increment that counter variable. It is not something you do in SQL or in trying to manipulate your query results. Quote Link to comment https://forums.phpfreaks.com/topic/276603-take-the-autoincrement-id-from-database-and-call-as-default-number/#findComment-1423968 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.