企划新闻点播系统 [英] Planning news ordering system
问题描述
记住在一个名为 sn_news
的表中有数千条新闻,其中一些新闻可能同时可供 X
客户端使用,但具有不同的 id
,我想知道如何实现新闻订购功能!
Having in mind that there are thousands of news in a table called sn_news
, where some news may be available for X
clients at the same time but with different id
, I was wondering on how to implement an news ordering feature!
在面板中显示客户 Y 的 X 条新闻,如下所示:
Showing X news for Client Y in its panel, like so:
ID Category Title
_______ __________________ ____________________________________________
1572709 Futbol Earthquakes Lluvia de goles en San José
1568657 Eventos Locales Maná rayó el sol de la Bahía
1562970 Deportes Locales SJ Earthquakes vence a RSL, es líder
1546516 Locales La magia de la música en la niñez
1546513 Locales 80 Años de Fotografía mexicana en SFMOMA
1546511 Locales Clases gratis de diseño solar en West Valley College
1546507 Locales Javier Sicilia visitó 12 de abril de 2012 Locales (noticias cliente)
1546504 Locales Celebrando el español a través de la poesía
1546502 Locales The National Hispanic University Receives Commendation from San Jose City Council
1546498 Locales Clases de costura en el CET
1546497 Locales Centro del Este de San José al servicio de la comunidad
1546481 Educacion Ayuda en español para elegir universidad
1546479 Educacion Aumentan programas de idiomas en escuelas públicas de California
1546478 Educacion Program uses visual arts as a better way to learn English
1546477 Educacion Niño hispano de 4 años es pintor
1546473 Educacion Perspectivas en el Sistema Educativo 2012
订购新闻的最佳方式是什么?
Which is the best way of ordering the news?
- 用 Y 更改新的 id X?
- 添加一个名为
news_order
的新字段,如果客户端有 20 个新闻,它将根据id
字段的顺序包含从 1 到 20 的数字,因此排序将始终在该领域完成? - 还有其他方法吗?
- Changing the new's id X with Y?
- Adding a new filed named
news_order
, where if the client has 20 news it will contain numbers from 1 to 20 according ordered by theid
field, and therefor the ordering will be always done upon that field? - Any other way?
希望我解释了我自己,如果没有,请告诉我!!
Hope I explained my self, if not, please let me know!!
所以只是为了澄清事情,这不是我的应用程序,我没有构建它并且是一个非常糟糕的代码我只需要更新"它并添加一些新功能.应用程序比较简单,但因为代码和一些数据库结构是很久以前实现的,从未得到改进",现在是后果.
So just to make clear things, it's not my app, I did not build it and is a really f*** up code I just need to "update" it and add some new features. The app is relatively simple, but because the code and some of the database structure was implemented long long time ago and never got "improved", now are consequences.
有一个日期字段,这就是检索新闻时它们的排序方式(抱歉弄错了).
There is a date field, and that's how they are ordered when the news are retrieved (sorry for the mistake).
不同id
的重复消息是由于应用程序的工作方式,它很复杂但合乎逻辑.
The repeated news with different id
is because of how the app works, it's complicated but logical.
推荐答案
除了唯一标识符外,您不应将 ID 字段用于任何其他用途.将其用于任何类型的功能(包括排序)都是不好的做法.
You should not use the ID field for anything else than a unique identifier. Using it for any sort of functionality, including ordering, is bad practice.
添加sort_order"字段是正确的解决方案.
Adding a "sort_order" field is the proper solution.
我仍然想知道您是否也没有发布日期的字段.如果您正在处理新闻,它似乎应该在某个地方.如果您有发布日期,那么最合适的做法是按该日期订购(大概是DESC").
Still I have to wonder if you don't also have a field for the publishing date. Seems like it should be in there somewhere if you're handling news. If you have a publishing date, then the most appropriate thing to do is to order by that (with "DESC", presumably).
但我也必须想知道,就像评论中的最低点"一样,为什么您对不同的客户有重复的条目.适当的解决方案是为客户提供一张表,一张用于新闻的表,然后是一个将它们绑定在一起的中间表.但这超出了您的问题范围,因此我将就此搁置.
But also I must wonder, like 'nadirs' in a comment, why you have duplicate entries for different clients. The appropriate solution is to have a table for clients, a table for news and then an intermediary table to bind them together. But that's outside of the scope of your question so I'll leave it at that.
这篇关于企划新闻点播系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!