Minase Posted December 12, 2009 Share Posted December 12, 2009 hello i want to create a database table like this this is the structure ID int autoincrement Type smallint a script will insert the values for Type what i want is when the Type is changed the ID to start again from 1 like insert into x.Type values(1) if i execute that query 10 times i should have 10 rows with values 1,1 | 2,1 | 3,1 | 4,1 | 5,1 etc now if i execute this query 10 times insert into x.Type values(2) i will have 11,2 | etc till 20,2 but i want it to be like 1,2 | 2,2 | 3,2 | etc thank you Quote Link to comment https://forums.phpfreaks.com/topic/184838-auto-increment-question/ Share on other sites More sharing options...
fenway Posted December 14, 2009 Share Posted December 14, 2009 I have no idea what you're talking about. Quote Link to comment https://forums.phpfreaks.com/topic/184838-auto-increment-question/#findComment-977298 Share on other sites More sharing options...
perpl3x3d Posted December 14, 2009 Share Posted December 14, 2009 I don't think autoincrement in the table structure is what you are really looking for then, but rather in the code itself. It seems like you want the first field to reset for every X amount of increments the other field increments. Like: function whatever($secondint, $XAMOUNT){ var $firstint = 1; while($firstint <= $XAMOUNT){ $q = "INSERT INTO TABLEHERE (firstfield, secondfield) VALUES ('$firstint', '$secondint')"; mysql_query($q); $firstint++; } That way if you called: $this->whatever(2, ; it would insert this: [1,2], [2,2], [3,2], [4,2], [5,2], [6,2], [7,2], [8,2] then for example call $this->whatever(3, 5); it would insert this: [1,3], [2,3], [3,3], [4,3], [5,3] Is that what you're going for? If not try and explain a little better.. Quote Link to comment https://forums.phpfreaks.com/topic/184838-auto-increment-question/#findComment-977350 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.