doufei8691
doufei8691
2012-11-19 23:01
浏览 40
已采纳

表格查找PHP中的数字数据

I have a fairly large table (~5 MB csv file) stored on our server that consists of purely numeric data giving some result based on two parameters, e.g.

A     B     Output
-----------------------
1     1     20
1     2     21
1     3     22
2     1     23
2     2     24
2     3     25
...   ...   ...

What I'd like to do is, based on the user's input, find the closest parameters then use the appropriate output. For example, using the table above, if the user select A=1.1 and B=2.9, the Output would be 22.

What is the best way to do this table lookup in php? Do I need to load the entire table into PHP? Instead of a csv-file, should I make it binary so that the file size is smaller and loads faster? Or should I create a mySQL database and perform a look-up that way?

TL;DR: I'm looking for the most efficient way to perform a nearest-neighbor table look-up on strictly numeric data.

图片转代码服务由CSDN问答提供 功能建议

我有一个相当大的表(~5 MB csv文件)存储在我们的服务器上,由纯数字数据组成 一些基于两个参数的结果,例如

  AB Output 
 ----------------------- \  n1 1 20 
1 2 21 
1 3 22 
2 1 23 
2 2 24 
2 3 25 
 ...... ...... 
   
 
 

我想做的是,根据用户的输入,找到最接近的参数,然后使用适当的输出。 例如,使用上表,如果用户选择A = 1.1且B = 2.9,则输出将为22.

在php中执行此表查找的最佳方法是什么? 我需要将整个表加载到PHP中吗? 而不是csv文件,我应该使它二进制,以便文件大小更小,加载更快? 或者我应该创建一个mySQL数据库并以这种方式执行查找?

TL; DR:我正在寻找最有效的方法来执行最近邻表查找 严格的数字数据。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doumigu9594
    doumigu9594 2012-11-19 23:11
    已采纳

    If mysql is available, my suggestion would be to use a table and do a look up. I guess rounding the user input to the nearest integer before lookup should give you the closest.

    点赞 评论

相关推荐