Reset Auto Increment to lower value [message #180127] |
Thu, 10 January 2013 17:55  |
makamo66
Messages: 4 Registered: January 2013
Karma: 0
|
Junior Member |
|
|
I need to create a tiles table that has a structure like this for http://www.myownmealplanner.com:
user_id sub_tile_id
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
etc.
I can't just create new tables for new users because I'm using cakephp and that would require new models, views, and controllers for every new table. How do I get the sub_tile_id to auto_increment starting at every new user id? According to the manual I can't restart auto-increment with a lower value than it has already displayed so this needs to be done with php somehow.
|
|
|
Re: Reset Auto Increment to lower value [message #180129 is a reply to message #180127] |
Thu, 10 January 2013 20:17   |
Denis McMahon
Messages: 634 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On Thu, 10 Jan 2013 09:55:59 -0800, makamo66 wrote:
> I need to create a tiles table that has a structure like this for
> http://www.myownmealplanner.com:
>
> user_id sub_tile_id 1 1 1 2 1 3 2 1 2 2 2 3 3 1
3 2 3 3 etc.
> I can't just create new tables for new users because I'm using cakephp
> and that would require new models, views, and controllers for every new
> table. How do I get the sub_tile_id to auto_increment starting at every
> new user id? According to the manual I can't restart auto-increment with
> a lower value than it has already displayed so this needs to be done
> with php somehow.
You could try using SQL something along the lines of:
insert into table ( user_id, sub_tile_id ) values ( 'current_user_id',
count( select sub_tile_id where user_id = 'current_user_id' ) + 1 );
I *think* something like that should increment sub_tile_id on a per
user_id basis, but it's not really a php solution, more of an sql one.
--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
|
|
|
|
Re: Reset Auto Increment to lower value [message #180133 is a reply to message #180132] |
Fri, 11 January 2013 13:55   |
makamo66
Messages: 4 Registered: January 2013
Karma: 0
|
Junior Member |
|
|
On Friday, January 11, 2013 5:05:54 AM UTC-5, Captain Paralytic wrote:
> On Jan 10, 5:55 pm, makam...@gmail.com wrote:
>
>> I need to create a tiles table that has a structure like this forhttp://www.myownmealplanner.com:
>
>>
>
>> user_id sub_tile_id
>
>> 1 1
>
>> 1 2
>
>> 1 3
>
>> 2 1
>
>> 2 2
>
>> 2 3
>
>> 3 1
>
>> 3 2
>
>> 3 3
>
>> etc.
>
>> I can't just create new tables for new users because I'm using cakephp and that would require new models, views, and controllers for every new table. How do I get the sub_tile_id to auto_increment starting at every new user id? According to the manual I can't restart auto-increment with a lower value than it has already displayed so this needs to be done with php somehow.
>
>
>
> If you are uaing MySQL then this is the default behaviour:
>
> http://stackoverflow.com/questions/3804845/auto-increment-usage-in-composit e-key
This didn't work
CREATE TABLE `tiles` (
`sub_tile` ENUM('1','2','3') NOT NULL,
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`user_id` INT(22)
)
|
|
|
Re: Reset Auto Increment to lower value [message #180134 is a reply to message #180133] |
Fri, 11 January 2013 14:05   |
M. Strobel
Messages: 386 Registered: December 2011
Karma: 0
|
Senior Member |
|
|
Am 11.01.2013 14:55, schrieb makamo66(at)gmail(dot)com:
> On Friday, January 11, 2013 5:05:54 AM UTC-5, Captain Paralytic wrote:
>> On Jan 10, 5:55 pm, makam...@gmail.com wrote:
>>
>>> I need to create a tiles table that has a structure like this forhttp://www.myownmealplanner.com:
--cut
>>
>>> I can't just create new tables for new users because I'm using cakephp and that would require new models, views, and controllers for every new table. How do I get the sub_tile_id to auto_increment starting at every new user id? According to the manual I can't restart auto-increment with a lower value than it has already displayed so this needs to be done with php somehow.
>>
>>
>>
>> If you are uaing MySQL then this is the default behaviour:
>>
>> http://stackoverflow.com/questions/3804845/auto-increment-usage-in-composit e-key
>
> This didn't work
what?
> CREATE TABLE `tiles` (
> `sub_tile` ENUM('1','2','3') NOT NULL,
> `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
> `user_id` INT(22)
> )
>
|
|
|
Re: Reset Auto Increment to lower value [message #180135 is a reply to message #180133] |
Fri, 11 January 2013 16:18   |
Captain Paralytic
Messages: 204 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On Jan 11, 1:55 pm, makam...@gmail.com wrote:
> On Friday, January 11, 2013 5:05:54 AM UTC-5, Captain Paralytic wrote:
>> On Jan 10, 5:55 pm, makam...@gmail.com wrote:
>
>>> I need to create a tiles table that has a structure like this forhttp://www.myownmealplanner.com:
>
>>> user_id sub_tile_id
>
>>> 1 1
>
>>> 1 2
>
>>> 1 3
>
>>> 2 1
>
>>> 2 2
>
>>> 2 3
>
>>> 3 1
>
>>> 3 2
>
>>> 3 3
>
>>> etc.
>
>>> I can't just create new tables for new users because I'm using cakephp and that would require new models, views, and controllers for every new table. How do I get the sub_tile_id to auto_increment starting at every new user id? According to the manual I can't restart auto-increment with a lower value than it has already displayed so this needs to be done with php somehow.
>
>> If you are uaing MySQL then this is the default behaviour:
>
>> http://stackoverflow.com/questions/3804845/auto-increment-usage-in-co...
>
> This didn't work
> CREATE TABLE `tiles` (
> `sub_tile` ENUM('1','2','3') NOT NULL,
> `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
> `user_id` INT(22)
> )
Why would it work, you haven't specified a composite primary key?
|
|
|
|
|
|
|