您的位置:首页技术文章
文章详情页

【求大神】现在有1000个string与一个MYSQL字典,查询这1000个string在MYSQL中的id并输出结果

【字号: 日期:2022-06-19 11:58:30浏览:53作者:猪猪

问题描述

1.这是需要查询string的示例(txt文件)vivo X5S LCHE-TL00HG621-TL00vivo Y51AKIW-AL10Samsung SM-G9200XiaoMi MI PADSamsung SM-G9008VXiaoMi MI 4CMX4 ProR7007ALE-TL00iPad3_4XiaoMi HM NOTE 1TDHUAWEI P7-L09iPhone8_4

2.在Mysql中有这样的一张表(示例)mid bid sid type productnamep1 mobile81 s000 mobile 多普达S900(Touch Diamond)p2 mobile81 s000 mobile 多普达T8388(麒麟)p3 mobile81 s000 mobile 多普达T8588p4 mobile81 s265 mobile 多普达S1(触动版)p5 mobile81 s000 mobile 多普达696p6 mobile81 s000 mobile 多普达838p7 mobile81 s000 mobile 多普达T2222(Touch Viva)p8 mobile81 s265 mobile 多普达S1p9 mobile81 s000 mobile 多普达T5399p10 mobile81 s267 mobile 多普达A6188p11 mobile81 s264 mobile 多普达D600(活力版)p12 mobile81 s000 mobile 多普达P800p13 mobile81 s000 mobile 多普达C720p14 mobile81 s264 mobile 多普达D600

3.需要查询1中在2中的结果并返回mid

问题解答

回答1:

$prodArr = explode('n',file_get_content(’prods.txt’)); // 获取txt中的文本并依据换行符将字符串转成数组$prods = implode(’,’,$prodArr); // 将产品数组转成where条件$sql = ’SELECT mid FROM prods WHERE 'productname' IN(’.$prods.’)’; // 组合查询Mid的sql

先暂时按照题主思路实现了一个,应该是题主想要的。

各位如果发现有啥错误可以使劲拍砖

回答2:

你这缺少 一层 键值对的关联关系,txt文件 中的 英文对应 数据表中的productname 其 product_code,这样查询太累人,不妨 用存储过程或者函数 或者 代码工具处理一下