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
https://forums.phpfreaks.com/topic/184838-auto-increment-question/
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..

 

Archived

This topic is now archived and is closed to further replies.

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