unique int id for a certain category in mysql
So the db str开发者_Go百科ucture looks like this
tablename(uniqueid, categoryname, categoryid)
I want to be able to generate a number that would be unique where categoryname="something"
Example, I can have the categoryname as 'something', and there are 5 different rows with the categoryid 1,2,3,4,5. and another categoryname as 'somethingelse', and there are 3 different rows categoryid of 1,2,3.
Since auto_increment wouldn't work, i was wondering if I can do that via php?
No, you just need to get auto-increment to work, are you sure that the uniqueid
column is set as the primary key
?
Also, why do you have both uniqueid
and categoryid
?
For example, your table creation query should have looked something like this:
CREATE TABLE categories (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
auto-increment can only be set on the primary key
of the database table and it can only be set on one column.
there is much more info about auto-increment in the MySQL doc: http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html
精彩评论