dpqvwgr74759 2012-10-10 11:00
浏览 175

通过php中的上/下箭头进行页面排序

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

  • 写回答

1条回答 默认 最新

  • douhuang9886 2012-10-10 12:50
    关注

    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
    
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献