简体   繁体   English

更改表格布局的最佳方法-PHP还是Javascript?

[英]best way to change table layout - PHP or Javascript?

Hello my fellow dev comrades! 您好我的开发同志们!

I am a C/C++ dev making my first entry into web development. 我是一位C / C ++开发人员,第一次涉足Web开发。 I'm making a soccer tournament scorecard. 我正在制作足球比赛记分卡。 PHP does the back-end processing to generate the scores. PHP执行后端处理以生成分数。 Javascript/CSS take care of the presentation. Javascript / CSS负责演示。 The screens keep transitioning like this(oops- cant attach a pic as I dont have enough reps!) 屏幕一直这样切换(抱歉,由于我没有足够的代表,所以无法附上图片!)

Edit: The rendering is messed up. 编辑:渲染混乱。 This is actually a 4x1 table, then a 2x1 table, then a 1x1 table. 这实际上是一个4x1表,然后是2x1表,然后是1x1表。

__________________
| Brazil 1       |
| Germany 2      |
__________________
__________________
| Italy 3        |
| Argentina 2    |
__________________
__________________
| England 1      |
| Holland 2      |
__________________
__________________
| USA 0          |
| France  2      |
__________________

USER CLICKS NEXT BUTTON 用户单击下一步按钮

_________________
| Italy  0       |
| Germany 2      |
__________________

__________________
| France 1       |
| Holland 3      |
__________________

NEXT BUTTON IS CLICKED 下一个按钮被选中

__________________
| GERMANY 2      |
| HOLLAND 1      |
__________________

So at first, you have the screen display results of 4 matches. 因此,首先,您将获得4个匹配项的屏幕显示结果。 Once you click the NEXT button, it displays the semifinal results. 单击“下一步”按钮后,它将显示半决赛结果。 And then the final match. 然后是决赛。

So as you see, the layout(number of rows) of the Scoreboard Table changes. 如您所见,记分板表的布局(行数)发生了变化。 How do I handle re-drawing the layout : I am thinking of having my PHP script churn out the entire tournament results and write them to a hidden/invisible element, and then have Javascript process this element and decide the layout based on what stage of the tournament we are at. 如何处理重新绘制的布局:我正在考虑让我的PHP脚本将整个比赛结果搅成一团,并将它们写入隐藏/不可见元素,然后让Javascript处理该元素并根据布局的哪个阶段决定布局我们参加的比赛。

Is this a sound approach? 这是一个合理的方法吗? Do we have a better way of doing this? 我们有更好的方法吗? My approach was based on that fact that it takes only one call to the server to extract results to minimize the loading time. 我的方法基于这样一个事实,即只需调用一次服务器即可提取结果,以最大程度地减少加载时间。

Thanks and cheers! 谢谢,加油!

Personally I would load each table into a tab using something like jQuery UI Tabs http://jqueryui.com/tabs/ 我个人将使用jQuery UI Tabs http://jqueryui.com/tabs/之类的东西将每个表加载到选项卡中

You could use other plug ins too but I tend to start with jQuery UI in most scenarios. 您也可以使用其他插件,但是在大多数情况下,我倾向于从jQuery UI开始。

A good way to do this is through Pagination. 一个好的方法是通过分页。 There are a number tutorials around (eg PHP pagination ) that will help you grab it. 周围有许多教程(例如PHP分页 )可以帮助您掌握它。 The approach you are taking is not scalable as once you have lot of data, pulling all of them in one go will slow the interface down and will not be optimised. 您采用的方法无法扩展,因为一旦您拥有大量数据,一次性将所有数据拖拉将减慢接口速度,并且不会进行优化。 In fact in majority of cases, user will not anyways browse through all the scores. 实际上,在大多数情况下,用户都不会浏览所有分数。

The basic idea behind around pagination is that you fetch only a fixed number of results only for that page. 分页背后的基本思想是,仅针对该页面仅获取固定数量的结果。 So you will need parameters like page number, results per page, total results to limit the results you want to fetch from DB and show the pagination links. 因此,您将需要诸如页码,每页结果,总结果之类的参数,以限制要从数据库中获取的结果并显示分页链接。 You can customise how the links work. 您可以自定义链接的工作方式。

Another way is to use Dynamic tables as well that can make your table dynamic in browsing and searching (will give you pagination by default) but that will only be client side implementation and the whole data will still be fetched from backend, which ideally is not scalable as I said. 另一种方法是也使用动态表,该表可以使表在浏览和搜索中保持动态(默认情况下将为您提供分页),但这仅是客户端实现,并且仍将从后端获取整个数据,理想情况下不是正如我所说的那样可扩展。 If you are sure that the data/table will not extend beyond a limit you can use this. 如果您确定数据/表不会超出限制,则可以使用它。 It makes the UI quite good in browsing and searching. 它使UI在浏览和搜索中相当出色。

Updating after your comment where you explained about the tournament. 在评论比赛的地方更新评论。 In this scenario, you can fetch all the data in one go. 在这种情况下,您可以一次性获取所有数据。 Then use jQuery to display the data dynamically. 然后使用jQuery动态显示数据。 Check this link Fifa World Cup 2014 . 检查此链接2014年国际足联世界杯 You can get some idea how you want to make your interface. 您可以了解如何创建界面。 Fifa World Cup's Match browser has a good UI to browse matches. “国际足联世界杯”的“比赛”浏览器具有不错的用户界面来浏览比赛。

You can use classes and IDs with jQuery to show and hide (and even scroll) to matches. 您可以在jQuery中使用类和ID来显示和隐藏(甚至滚动)匹配项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM