PHP MySQL查询算法帮助算法、PHP、MySQL

2023-09-11 06:21:22 作者:不忘初心.

我是一个设计一个网站,它的票数和年龄订单的结果。

我发现reddit的算法,我认为这是最好的使用。但是,我不知道如何实现这一到PHP。我已搜查谷歌如何做到这一点,但我无法找到任何结果。我不知道,如果它只是意味着,因为我不知道到底是什么,我应该寻找。

不过,我知道基本的PHP,有没有一种简单的方法这样做的方式。

是否有可能做这样的:

SELECT * FROM表顺序algorithm_here DESC;

的书签交易算法如下:

  LOG10(Z)+((Y * TS)/ 45000)=排名

A =时间公布

B = 00:00:001时1/1/2010

U =选票

D =向下票



TS = A-B


X =ü-D


Y =

1如果x大于0

0如果x = 0

-1如果x℃的


Z =最大值(ABS(x)中,1)
 

解决方案

那么,如果它的我,我会写一个UDF在MySQL中被称为可能是reddit_algo或东西,使用它像

  SELECT
    *
    reddit_algo()作为评价
从
    `table`
ORDER BY
    `rating`
LIMIT 30;
 

使用PHP连接MySQL数据库 创建表 php mysql

I'm a designing a website that orders results on its votes and ages.

I found the reddit algorithm and I think that is the best to use. However, I do not know how to implement this into php. I have searched google on how to do this but I cannot find any results. I don't know if it is just mean because I do not know exactly what I should be searching.

I know basic PHP however, is there a way of doing this in a simple way.

Is it possible to do it like this:

"SELECT * FROM table ORDER BY algorithm_here DESC";

The reddit algorithm is as follows:

Log10(Z) + ((Y*Ts)/45000) = rank

A = time posted

B = 00:00:001 am 1/1/2010

U = Up votes

D = Down votes



Ts = A-B


X = U-D


Y =

1 if x>0

0 if x=0

-1 if x<0


z = max(abs(x),1)

解决方案

Well if its me, i will write an UDF in MySQL called may be reddit_algo or something and use it like

SELECT
    *,
    reddit_algo() as rating
FROM
    `table`
ORDER BY
    `rating`
LIMIT 30;