the mode you work with the database is wrong:
using like will slow down the whole database for much.
try:
3 tables:
categories: id | timestmp | title | etc
galleries : id | cat_id | timestmp | title | etc
pictures: id | cat_id | gal_id | timestmp | title | url
indexes on ids, timestmp cat_id and gal_id
querying for all categories:
SELECT id,timestmp,title,etc FROM categories
querying for all galleries in the category:
SELECT id,cat_id, timestp, title, etc FROM galleries WHERE cat_id = '1'
querying for pictures in the gallery:
SELECT id, cat_id, gal_id, timestmp, title, url FROM pictures WHERE cat_id = '1' AND gal_id ='2'
so you will be able to work much easier with the pictures, and mysql querying only for integer values will be about 100 times faster than the query for '%LIKE%' .
and NEVER use "SELECT *" because it's slower...