从mysql数据库中选择类似的值

mat*_*hew 1 php mysql

我在MySQL数据库中有几个数据.在我的表中有一个名为rank的列.我要的是,当有人进入秩说,25那么结果应该显示类似的名称(+或- )的行列LIMIT,以10从表中.

mathew - 25
john - 26
joe - 25
stewart - 27
kelly - 24
brandon -23
magy - 22 .......etc.
Run Code Online (Sandbox Code Playgroud)

谢谢马修

cod*_*ict 5

您可以使用MySQL的betweenlimit子句:

$range = 5;  // you'll be selecting around this range. 
$min = $rank - $range;
$max = $rank + $range;
$limit = 10; // max number of results you want. 

$query = "select * from table where rank between $min and $max limit $limit";
Run Code Online (Sandbox Code Playgroud)