基于MySQL的Web应用程序:用户选择订单或商品的最简单方法? [英] MySQL based web app: Easiest way for users to choose order or items?

查看:93
本文介绍了基于MySQL的Web应用程序:用户选择订单或商品的最简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究用户可以重新排列项目的东西,以后,这些项目需要按选择的顺序显示.举一个简单的例子,考虑一个项目列表:

I'm working on something where users can rearrange items, and at a later time, those items need to be displayed in the order chosen. As a simple example, consider a list of items:

A,B,C,D,E,F,G.
MySQL表很简单:user_id,字母,排序号

A, B, C, D, E, F, G.
The MySQL table would be something simple: user_id, letter, sortnumber

允许用户逐步更改顺序.他们可以将A移到D之后,将G移到开头等.除此之外,他们还可以添加和删除项目.因此,他们可能会删除C或添加X.在每个步骤中,我都将数据发送到PHP,PHP将对其进行处理,并在MySQL中设置各项.

The user is allowed to change the order in incremental steps. They might move A to after D, G to the beginning, etc. In addition to this, they can add, and remove items. So they might delete C, or add X. In each of these steps, I send data to PHP, which will process it, and set the items in MySQL.

我认为有两种解决方法:

There are two ways I see going about this:

  1. 每次添加/删除/重新排序 东西,将整个列表发送到 PHP,删除所有数据 以前在那里 插入新列表.问题是 这很多 每次删除/插入 做任何事情.他们可能将A移到B之后,然后突然我删除了7条记录,并再插入7条记录.从好的方面来说,这很简单.

  1. Each time they add/remove/reorder something, send the entire list to PHP, delete all the data they previous had in there, and just insert the new list. Problem is, this is a lot of deletions/insertions each time they do anything. They might move A to after B, and then suddenly I delete 7 records, and insert 7 more. On the plus side, it's dead simple.

他们每次移动"(例如添加,删除或重新排序),都为此发送信息.例如.他们将A移到F之后,并告诉我将F移到F之后",我现在必须检查列表中是否同时存在A和F,然后我必须递减A和F(包括F)之间的所有"sortnumber".如果他们说删除Z",则必须在列表中找到它,将其删除,并减少其后所有记录的排序数.

Each "move" they do (e.g. an add, or a remove, or a reorder), send the information for that. E.g. they moved An after F, and tell me "move An after F" I now have to check that both A and F exist on the list, then I have to decrement all "sortnumber" between A and F (including F). If they say "delete Z" I have to find it on the list, delete it, and decrement all sortnumbers of records after it.

所以我很好奇...是否有人必须处理订单重要的事情,如果是的话,您如何处理呢?

So I'm just curious... Has anybody had to deal with something where order matters, and if so, how did you go about it?

推荐答案

向表中添加序列"列-作为浮点数.

Add a Sequence column to the table - as a floating point number.

当某项在A行和B行之间移动时,请将其序列号设置为这些相邻列的平均值.

When an item is moved between Row-A and Row-B set its sequence number to the Average of those adjacent columns

索引序列"列:)

这篇关于基于MySQL的Web应用程序:用户选择订单或商品的最简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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