Is it possible to do a wildcard search, and extract the values of the wildcards and put them into a MySQL result? Preferably, I'd also like to label the wildcards. Continue reading to see what I mean.
EXAMPLE: Consider a database table with the following structure.
+----+-------------------+
| id | content |
+========================+
| 1 | %1.%2.%3 |
+----+-------------------+
| 2 | Hey %name. |
+----+-------------------+
First, note that this is just an example. I am not storing multiple values in a single database field. See here: Is storing a delimited list in a database column really that bad?
Instead, I want to know if it is possible to have wildcards in a database, and then compare that with user input. In other words, I would like to take user input, such as 2.bla.^7
or similar, and then return that respective row--%.%.%. I would then like to take those wildcards, and return them as part of the MySQL result. Below is an example PHP mysql_fetch_assoc()
result based on what I'm looking for. The result obviously doesn't need to be laid out exactly like this, but this is the sort of result that I'm looking for.
EXAMPLE:
/************************
* Input: 2.bla.^7 *
************************/
Array
(
[0] => Array
(
[id] => 1,
[content] => %1.%2.%3
),
[1] => Array
(
[1] => 2,
[2] => bla,
[3] => ^7
)
)
/************************
* Input: Hey Matt. *
************************/
Array
(
[0] => Array
(
[id] => 2,
[content] => Hey %1.
),
[1] => Array
(
[name] => Matt
)
)
I understand that what I'm looking for is likely fairly complicated, or specialized for my unique case. If you can point me in the right direction, I would hugely appreciate it! I don't even know if this is possible--if it's not, an alternative solution would be greatly appreciated! However, I want the database structure to stay as close to the same as possible.
Thank you so much!