Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有User一个名为point.
User
point
User与所有其他行相比,如何获得实例的排名。
用户的排名可以被认为是比他们多的其他用户的数量加上 1。正如 Mischa 在评论中指出的那样,一个合适的位置是在 User 模型本身中,如下所示:
def ranking User.where('point > ?', point).count + 1 end
然后,您可以将其称为:
Rank: <%= @user.ranking %>
这样做的缺点是在相同排名中对具有相同点数的用户进行排名。你必须为这种情况决定一个“决胜局”。
我已经为 Yii 下载了一个模块库,其中每个 PHP 文件都以此开头:
<?
...而不是:
<?php
在我的本地 Apache 服务器上,这些文件被加载为平面文件,而不是作为可执行脚本,尽管这些文件都被修改为可写和可执行的。有没有办法强制这些文件作为