使用php通过前端重新排序数据库记录行 [英] Reorder the database record rows through front-end using php

查看:22
本文介绍了使用php通过前端重新排序数据库记录行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PHP/MYSQL.我希望在我的前端,用户可以在较早的阶段对用户自己输入的数据库记录进行排序和重新排列.用户上传的记录有时可能会随机插入到数据库中,因此在用户配置文件中,他/她可能有能力根据那里重新排列数据库中的行.

I am using PHP/MYSQL. I want in my frontend, for the users to sort and rearrange database records entered by the user himself in an earlier stage. The records uploaded by the user may sometimes inserted into the database randomly, so in the user profile he/she might have a facility to rearrange the the rows in the database according to there wise.

谁能给我一个脚本来帮助我这样做.

Can any one provide me a script that would help me to do so.

id  title     date     desc
1   s1        s1_date  s1_desc
2   s2        s2_date  s2_desc
3   s3        s3_date  s3_desc
4   s4        s4_date  s4_desc
5   s5        s5_date  s5_desc

在用户配置文件中,他想重新排列行,以便 s2 向上移动,并为每个字段保存为 s2->s1 和 s1->s2 .. 可能会在两者之间交换记录

In the user profile he want to rearrange the rows so that s2 will go one up and will save as s2->s1 and s1->s2 for every field.. may be swapping of records in between

我正在以另一种方式查看它.. 用户页面将按行显示该字段,并且在侧面将有一个输入框,每个当前行 id 说 (id) 被设置为该输入框的值,因此用户可以在两者之间进行更改并将整个重新排序的列表提交给后端.在这种情况下,我们能做什么...同时会有很多交换...

I am looking it in another way.. user page will show the field in rows wise and in the side there will be an input box of each the current row id say (id) is set as value of that input box so that the user can change in between and submit the whole reordered list to the back-end. In that case what can we do... there will be many swapings to to concurrently..

推荐答案

最好的解决方案是添加另一个字段ordering",您可以在其中默认存储 int ID,并且在重新排列行时,您可以在这些行之间交换排序值.在查询中,您将按顺序排列 ASC/DESC

Best solution is to add another field "ordering" where you can store by default int ID, and while rearranging rows, you could swap values of ordering between these rows. In query you would do ORDER BY ordering ASC/DESC

这篇关于使用php通过前端重新排序数据库记录行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆