在数据库中查找与用户在php中输入的内容最接近的数字匹配 [英] Finding the nearest numeric match in a database to what a user has inputted in php

查看:183
本文介绍了在数据库中查找与用户在php中输入的内容最接近的数字匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到一种在数据库中查找字段的方法;在数字上,壁橱与用户在Web表单中输入并提交的壁橱匹配.

I need to find a way in which to find a field in a database which; numerically, is the closet match to what a user has inputted in a web form and submitted.

更深入的解释:

在数据库表中有两行,其字段条目分别为80.1和80.7.如果站点用户在Web表单的输入元素中输入80并提交该值,则处理脚本将查找该表并查找具有80.1的行,并将其选择为壁橱匹配项.

In a database table there are two rows with a field entry of 80.1 and 80.7. If a site user enters 80 into an input element on a web form and submits that value, the handling script looks up that table and finds a row with 80.1 and chooses this as the closet match.

如果是相反的方式,即用户输入一个浮点整数(80.6),则该表会寻找最接近的四舍五入数字,即(90),这很容易.我显然丢失了一些东西,并认为将为此使用PHP中的内置函数.

If it was the other way round, i.e. the user entering a floated integer (80.6), the table looking for the nearest rounded number i.e. (90) that would be easy. I'm obviously missing something and thought there would be an in built function in PHP for this.

很抱歉,如果我不能很好地说明自己,请告诉我.

Apologies if I have not explained myself well, if so please let me know.

推荐答案

尝试一下

SELECT * FROM `table_test1` where `price` > 80 order by `price` asc limit 1

这篇关于在数据库中查找与用户在php中输入的内容最接近的数字匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆