dsjuimtq920056 2018-03-27 05:07
浏览 116
已采纳

选择行包含字符串的位置

I have a column named software_hardware from the table activities which could have multiple product inputs separated by a pipeline like INVENTORY| POS | or GPOS | ACCOUNTING |.

I have this query:

SELECT a.id, a.ticket_number, a.client, a.software_hardware, 
a.issues_concern, a.status, a.technical_programmer, a.date_added 
FROM activities a
WHERE a.client = '".$_POST['client']."' AND a.software_hardware LIKE '%".$arr[$i]."%'
ORDER BY date_added DESC

$arr = explode("|", $_POST['Soft_hard']);

When I select a client and a product, related info would be displayed on a div. Now my problem is, if I have POS and GPOS, I realized I couldn't use LIKE '%[input product name here]%'as this would return results that contains both POS and GPOS if I selected POS.

How can I fix this query to not display GPOS if I selected POS?

PS. I am aware of the issues with MySQL. It's what the company I'm in uses so I have no choice at the moment.

  • 写回答

2条回答 默认 最新

  • doukong9982 2018-03-27 05:14
    关注

    You can use REGEXP:

    a.software_hardware REGEXP '[[:<:]]" . $arr[$i] . "[[:>:]]'
    

    the [[:<:]] and [[:>:]] markers stand for word boundaries. So POS cannot match GPOS as there would be no word boundary at the beginning.

    Note you will need to trim($arr[$i]) if it has leading or trailing whitespace.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀