Jump to content

Mysql and php combination


Mumlebumle

Recommended Posts

Hi,

 

Can i make so the mysql columns cant have the same number, such as if the row 1, column 1 have the value 30, and then the row 2 column 1 cant be 30, but can be 31?..

 

The problem is i have an auto increment id before thoose, and then the stuff being added will just keep being added, but just to a new id. hereby more of 1 type can occur.

 

$sql = "INSERT INTO reimburse VALUES ('','$reimbursekillid','')";

mysql_query($sql)or die(mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/210976-mysql-and-php-combination/
Share on other sites

my your ID column the Primary column, set it as INT, and then set AUTO_INCREMENT on the column itself. This way unless you go changing the ID value through your scripts it will always be unique. If for some reason the row does manage to get and try to set a value already used it should throw an error as i think a primary ID column is also automatically set as unique which means it shouldn't allow a value that's already being used.

 

Alternatively you can make your own auto increment system lets say if you want you're values to start at 20000 and count up rather than starting at 1 and going up from there.. but all in all its the applying the same idea, and in the case of your own your just making extra calls to the DB to increment a number and insert it else where.

my your ID column the Primary column, set it as INT, and then set AUTO_INCREMENT on the column itself. This way unless you go changing the ID value through your scripts it will always be unique. If for some reason the row does manage to get and try to set a value already used it should throw an error as i think a primary ID column is also automatically set as unique which means it shouldn't allow a value that's already being used.

 

Alternatively you can make your own auto increment system lets say if you want you're values to start at 20000 and count up rather than starting at 1 and going up from there.. but all in all its the applying the same idea, and in the case of your own your just making extra calls to the DB to increment a number and insert it else where.

 

Thanks, i found the unique button beside the primary and used that one, it worked, now getting Duplicate entry '30' for key 'kill_id' :D:D

If you don't have a lot of data built up yet, it may be in your best be to just "EMPTY" the whole table it leaves the structure but everything in it that stored is wiped out of it. Chances are since your applying the auto_incriment / unique to a table thats already been built and used its running into that error you gave cause the auto incriment value in the tables "Operations" tab is either below a number already existing in the table or. You have 2 or more rows where the ID is the same.

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.