How to update the data sequence number from PHP?

  mysql, php

I have product list in database and want to mange sequence from the administrator.

If i enter new product in database it will be come 1. (there is already 6 record 1,2,3,4,5,6) new product will be sequence 1. new sequence will be 1,2,3,4,5,6,7 and new record will be come on 1.

if during insert new record i want to come on 3rd position than other position number 3 become 4 and position number 4 become 5 and so on.

I am using MySQL and PHP.

I got the answer when admin will add the product we got the new product always as 1st position by using below query:-

// be default position will set as 0

insert into user(name,inum) values(‘product name’,’0′);

SET @i = 0;

UPDATE user SET inum = @i := @i + 1 ORDER BY inum;

What i need to do if i want to insert new record on position 3 and rest of the record position will increase by 1.

Source: Ask PHP

LEAVE A COMMENT