
lol, this could be difficult
you should split your tables up, one for categories, one for pictures, one for users, etc... so things are organized better, as far as the link between categories, you could do that pretty easy through mysql
in your categories table, create an integer field, and let mysql auto increment that field, so then your query for say category a with an id of 1 would be select * from categories where id = '1';
why not use a premade php gallery?