MySQL PDO查询类似PIPES [英] MySQL PDO query LIKE with PIPES

查看:47
本文介绍了MySQL PDO查询类似PIPES的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PDO语句,该语句应该查找周围带有管道的数据,我在单个列中存储了多个ID.我知道这不是很好,但是这似乎是存储数据的逻辑方法.

I have a PDO statement which is supposed to look for data with pipes around it, I have multiple id's stored in a single column. I know this isn't great but it seems the logical way to store the data.

列内容示例| 1 | 3 | 4 | 5 | 14 | 76 |

Column content example |1|3|4|5|14|76|

所以我想在数据库中找到每行中有3行.我使用php表单发布或获取3

So I want to find every line in the database with 3 in it. I use a php form to post or get 3

    $getthis = $_GET['getthis'];
    $sql = "SELECT * FROM table WHERE types LIKE '?' ORDER BY name";
    $q = $conn->prepare($sql);
    $q->execute('%|$getthis|%');
    while ($data = $q->fetch()) { do something }

不好,我尝试过各种方法来做,但是每次我都惨败.

Its not good, Ive tried various ways of doing this but I fail miserably every time.

谢谢您的帮助,顺便说一下,我们的网站很好!它帮助我加载

Thanks for your help in advance and great site by the way! Its helped me loads

编辑-感谢您的帮助,除非限制项目应包含的子类别的数量,否则我无法真正更改结构.因为这就是本专栏的内容,所以袜子可能在footware [1]和footfootors [4]下,可能还有其他20个subcats下

EDIT - Thanks for your help, I cant really change the structure unless I limit the number of sub-categories an item should be under. As this is what this column contains (so socks could be under footware[1] and footprotectors[4] and possibly 20 other subcats

我会尝试使用此方法'find_in_set',但是对于为什么需要大于零的原因我感到困惑?再次感谢!

Ill try this method 'find_in_set' but im confused as to why it needs to be higher than a zero?? Thanks again!

推荐答案

您可以使用 查看全文

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