The title could be confusing, but I think my doubt is clear.
I’ll explain. I’m doing this query:
$sql = 'SELECT * FROM calendar WHERE day = "'.$day.'" AND month = "'.$month.'" AND year = "'.$year.'" AND realizada = 0 AND colaborador = "What to put here?!"';
But the field “colaborador” is a serialized array.
One example, when I print_rthe value of my array after unserialize it’s something like this:
Array ( [0] => l3gion [1] => Someone [2] => teste )
Imagine that I want to search for “l3gion” in the previous Query, how can I do this?
Thank you.
l3gion
If you need to query individual elements from your array, don’t store the serialized array. Store each element on an individual row in a child table, and associate it with the primary key value of your calendar table:
This is the normalized approach.
If you must store the serialized array, you might check out How FriendFeed Uses MySQL to index “schemaless” data. But that also involves creating new tables for the indexes.
If you really can’t create any new tables or indexes, you can try to use
LIKEorREGEXPbut both of these solutions will be very inefficient and error-prone.You’re screwed.