Jump to content

auto increment question


Minase

Recommended Posts

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

Link to comment
Share on other sites

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..

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.