MySQL 字段值通配符?
我正在尝试构建一个简单的系统,用于在将某些值输出到用户的文件中之前对其进行翻译。假设我有文本:“方法(aaaabbbccc - 随机文本)”,我试图让用户将其转换为他们想要的任何内容。我已经构建了一个转换表,在该表中用户将输入“Method *”=>; “描述”,这基本上意味着他们希望将文本“方法”后跟任何内容(* = 通配符)简单地翻译为“描述”(或他们想要的任何其他文本)。
如果我有一些信息:
Method (aaaabbbccc - random text)
Method 2 (test - text)
Method3
这应该转换为
Description
Description
Method3
由于最后一行不满足用户定义的过滤器,因此它不会被转换。
我认为实现这一点的最简单方法是对每一行执行查询:
SELECT new_text FROM table WHERE old_text LIKE 'Method 2 (test - text)' etc.
但是由于 old_text 是“Method *”,因此 * 需要转换为通配符,并且 MySQL 在执行搜索时需要处理这个问题。我尝试的每个组合(甚至将 old_text 存储为“Method %”)似乎都不起作用。
希望有人可以提供一些指导来构建这样的系统,用户可以定义过滤器,然后让 MySQL 对这些过滤器进行操作。
I'm trying to build a simple system for translating some values before they are outputted in a file for users. Let's say I have the text: 'Method (aaaabbbccc - random text)', I'm trying to let the user convert this to anything they want. I have built a table for conversions, and in this table the user would enter say 'Method *' => 'Description', which basically means they would like the text "Method" followed by anything (* = wildcard) to be simply translated into 'Description' (or any other text they would want).
If I had some info:
Method (aaaabbbccc - random text)
Method 2 (test - text)
Method3
This should be converted into
Description
Description
Method3
As the last line does not satisfy the filters as defined by the user, it does not get converted.
I thought the simplest way to achieve this would be to perform a query for each row:
SELECT new_text FROM table WHERE old_text LIKE 'Method 2 (test - text)' etc.
But since old_text is 'Method *' the * needs to be converted into a wildcard and MySQL needs to handle this when performing the search. Every combination I try (even storing old_text as 'Method %') doesn't seem to work.
Hoping someone can provide some pointers for building a system like this where users can define filter and then have MySQL operate on those filters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 mysql /(使用 phpmyadmin)中完成。这是结果输出屏幕(希望您能解释意大利语):
Visualizzazione record 0 - 1 (2 Totali, La query ha impiegato 0.0010 sec)
SELECT *
来自
表
WHERE txt LIKE 'method %'
id txt
好吧?
Did it in mysql /(using phpmyadmin). This is the resulting output screen (hope you interpret italian):
Visualizzazione record 0 - 1 (2 Totali, La query ha impiegato 0.0010 sec)
SELECT *
FROM
tabl
WHERE txt LIKE 'method %'
id txt
Allright so?
我认为你需要这样的东西:
哪里:
old_text
是“方法(aaaabbbccc - 随机文本)”
,user_entry
是'Method *'
并且new_text
是'描述'
I think you need something like this:
where:
old_text
is'Method (aaaabbbccc - random text)'
,user_entry
is'Method *'
andnew_text
is'Description'