I’m trying to auto increment the art_id in the table below based on the art_userid, Is this possible without writing any extra php code? The gen_id has to remain and cannot be removed. I’m using Mysql and Php
CREATE TABLE `articles` (
`gen_id` INT(10) NULL AUTO_INCREMENT,
`art_id` TINYINT(3) NULL DEFAULT '0',
`art_userid` INT(10) NULL DEFAULT '0',
`art_title` VARCHAR(150) NULL DEFAULT NULL,
PRIMARY KEY (`gen_id`)
So in the end, if user 1 posted an article, his art_id would be 1. The next one he posts would have the id 2.
But if user 2 posted and article, his art_id would be 1 again. The next one he posts would have the id 2. Not the continuation of the 1st users art_id.
gen_id | art_id | art_userid | art_title
-----------------------------------------
1 1 1 Title A
2 2 1 Title B
3 1 2 Title A
4 2 2 Title B
5 3 1 Title A
Well, I kinda solved it, but with one less column. The engine type needs to be MyIsam for this. Then do a create like this:
Then when you insert art_userid, you’ll get a unique value for art_id starting from 1 for each user.