mysql - php+mysqlupdate
I have the following mysql table data where primary key is (id,seq)
id name seq
Now what i have to do is delete the 1st row and reduce the values of seq in remaining rows by 1
I am using php PDO. And i have deleted the first row and then fetched the remaining rows in $result and then did following
{-code-2}
I am getting following error
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry for key 'PRIMARY'
could anyone help me on this?
Answer
Answer
Solution:
I don't know if I understood your problem right, but if this while statement:
Loops through rows "b", "c" and "d", the problem is that, with the first loop, the values of "seq" for b, c and d are 1, 2, 3, and then in the second loop, the values of sec for b, c, and d would be 1, 1 and to. Maybe it's the problem. I think what you should do is: 1) Delete the first row 2) Execute the query just once
You could take the id from the deleted row. Besides, just to make sure everything works, you should add an order by statement to your query:
I hope it helps!
Answer
Solution:
because you set primary key (id,seq) together. and basic property of primary key is that..it would be unique and not NULL. so uniqueness of the combination of id and seq must be violated thats why u r getting below error.
REFERENCE