0

I have a sql table 'sample' with 3 fields id,content, arrange. The field arrange gives the order to be displayed contents in html page.

 --------------------
 id|content|arrange
 --------------------
 1   A        4
 2   B        5
 3   C        1
 4   D        3
 5   E        2
-------------------

When use the query

SELECT content FROM sample order by arrange

gives me result in the order

 ----
 C
 E
 D
 A
 B
 ----

My question is how we can change the positions and update it in Database?

For example I need to move value 'A' to position of 'C', and all other contents should be relatively updated.

how can we do that?

3
  • 1
    Take a look at jqueryui.com/sortable Commented Nov 30, 2013 at 6:26
  • SELECT content FROM sample order by arrange will arrange recordset . it will never gives result as you given. Commented Nov 30, 2013 at 6:26
  • I'm taking the values of table 'sample' to display content based on arrange field value. Commented Nov 30, 2013 at 6:31

1 Answer 1

2
SET @i=0;
SELECT content , @i := @i +1 AS NewOrder
FROM sample
order by arrange

in PHP, read dr['NewOrder'] and update it to db?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.