This is my mysql query:
SELECT *
FROM wp_bp_group_documents
WHERE group_id = 4
AND id IN (2)
AND (file LIKE '%jpg'
OR file LIKE '%png'
OR file LIKE '%jpeg'
OR file LIKE '%gif')
ORDER BY created_ts DESC LIMIT 0, 20
and this is my table structure:
'id', 'user_id', 'group_id', 'created_ts', 'modified_ts', 'file', 'name', 'description', 'featured', 'download_count'
'1', '1', '1', '1301587327', '1301587327', '1301587327-NewApplicationForm.pdf', 'Tenancy application form', 'This is a tenancy application form. Please download and fill in.', '0', '0'
'2', '1', '4', '1301934439', '1302005432', '1301934439-bupa_large.png', 'BUPA Stand Image', 'asd', '0', '0'
So from this query I expect it to find the second record in the database, however it returns no values.
There are no mysql errors. I'm just wondering if I've done the query right?
Thank you
file
is a MySQL keyword. Try wrapping the file
name in backquotes: `file
`.
Your id column appears to be a string, but you're specifying an integer in the array. Could that be the problem?
Slightly off the OP's topic, but you know (right?) that when you include "like" in any select, then MySQL has no choice but to read through the entire table. To avoid that, some folks try to make sure that values like filetypes -- things that already, by definition, lend their own taxonomy -- are broken out as non-unique indices.
If you decide to do that, your table suddenly becomes unnormalized. To remedy that, the table needs another column, say `pictype`, that you'd index. To me, that's a stronger table design anyway, but it's just MHO.