Searching for needle in haystack (php/mysql)
Posted: Fri Jun 23, 2006 12:48 am
Hi All,
In a field called "savedata" in a table (MySQL), we store data like:
1|3|5|10
It's basically a list of numbers that correspond to data from an array set.
I'm trying to search it with PHP and not having much luck.
Currently using:
PHP Code:
if record A has savedata = 1
and
record B has savedata = 12|14|7|1|2
then the above PHP code only finds record A even though record B has a 1 as well. I tried replacing the pipe character with a space so the numbers appears as words rather than a single string. No luck as well.
I tried LIKE '%1%' with no luck.
This seems more a MySQL problem than a PHP one.
Is there a way to do this or perhaps store the data differently in the field so that its searchable?
Best,
Cent
In a field called "savedata" in a table (MySQL), we store data like:
1|3|5|10
It's basically a list of numbers that correspond to data from an array set.
I'm trying to search it with PHP and not having much luck.
Currently using:
PHP Code:
Code: Select all
$query = "SELECT * FROM database.table WHERE savedata LIKE '1'";if record A has savedata = 1
and
record B has savedata = 12|14|7|1|2
then the above PHP code only finds record A even though record B has a 1 as well. I tried replacing the pipe character with a space so the numbers appears as words rather than a single string. No luck as well.
I tried LIKE '%1%' with no luck.
This seems more a MySQL problem than a PHP one.
Is there a way to do this or perhaps store the data differently in the field so that its searchable?
Best,
Cent