Can anybody help me to order the pages custom CMS pagemanager done in php ?
I have a database table in which page(article) managing. id - parentId - content- title - order - etc
I selected and displayed this in html table as a tree order(parent then child likewise).. where i put edit/delete options and also one column to ORDER the pages , I want order column with up/down arrows .. and when clicking on that it should swap corresponding Order field of database table(it contains some numbers). The problem is that here it contains parent and its children so arrows should be placed in correct order ... ie do not swap a child and parent. only column with same parent id (if there) should be swapped..
As you didn't provide code or database structure, I'll try to explain a basic ordering system, i hope you got the idea how to solve your problem.
Imagine these are your data in your mysql table:
id - parent - title - order
1 - 0 - abc - 1
2 - 0 - xyz - 2
3 - 1 - 123 - 1
4 - 1 - 456 - 3
5 - 1 - 789 - 2
If you make a query like this:
SELECT ... ORDER BY order, id ASC
You'd have a tree like this:
- root (id:0)
|
|___ abc (id:1)
| |___ 123 (id:3)
| |___ 789 (id:5)
| |___ 456 (id:4)
|
|___ xyz (id:2)
If you click on entry 789
(id:5), to give it a higher order than entry 123
, your SQL query should be something like this:
UPDATE table SET order = order + 1 WHERE order = order - 1 AND parent = 1
The next query:
UPDATE table SET order = order - 1 WHERE id = 5
Your Tree should be something like this then:
- root (id:0)
|
|___ abc (id:1)
| |___ 789 (id:5)
| |___ 123 (id:3)
| |___ 456 (id:4)
|
|___ xyz (id:2)
if you need a more flexible way, you can use something like this also:
(here I supposed that you have 100 rows ordered from 1 to 100, and you want to move id:33 to a place after id:51)
UPDATE table SET order = order + 1 WHERE order >= 51
UPDATE table SET order = 51 WHERE id = 33
UPDATE table SET order = order - 1 WHERE order BETWEEN 33 AND 50