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

Link to comment
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.

 

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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