![]() |
SQL problem
My problem is thus:
I am creating a PHP/MySQL gallery and have Galleries that hold pictures. Galleries can also have sub galleries. Now I want to be able to delete a Gallery only if it has no pictures in either itself or ANY of its sub Galleries. But Galleries can have any number of sub galleries. So I could have a situation like this: code: Whereby I don't want to be able to delete "Top Gallery" because then I wouldn't be able to access any of the sub galleries and thus any pictures in the sub gallery. This wouldn't be so bad if it wasn't also possible to have a gallery that only contained a sub-gallery and not pictures. What I want to find out is 1) Will deleting the Gallery leave me with any "hanging" pictures, and if so, which ones? 2) Will deleting the Gallery leave me with any "hanging" galleries, and if so, which ones? My DB tables are thus: code: code: Where t_pictures_group.parent links to t_pictures_group.id to form the tree heirarchy and pictures.group_id links to t_pictures_group.id. You can ignore t_pictures_group.pic_id, that's for something else altogether. I don't have any experiance of using tree structures in SQL and want to exaust all options before I start looking at writing a mamoth cursor script. Any takers? |
Re: SQL problem
Quote:
|
Quick Question: Where on the server is the pictures being hold?
SQL only handles the information as to where the file is located. You delete the info in the SQL table, it is still on your server. -Duane |
Deleting a picture where the address is known (probably pictures.name) is fairly simple though, Duane -- I think it's the SQL specifically that Phily's wanting help with. Although Phily, I'm not sure why you're using a database for this -- since your schema doesn't (as far as I can tell) allow for membership of multiple groups, couldn't you just use a folder hierarchy and file attributes? The DB is probably faster though, I guess.
My SQL is atrocious, but I think you want to do some kind of recursive query here. No idea how to go about it, though, sorry. |
I know just enough SQL to get me into trouble. :p But this caught my eye...
code: Wouldn't this try to set a not-null value to a null default? I'm sure I could be completely wrong, so maybe someone else could confirm this. And I know this doesn't address your original question, but I wanted to point it out just in case. |
NULL is a seperate value to an empty string if I remember correctly, Scor.
|
NOT NULL meaning you're setting the NULL attributes of a table to NOT NULL
|
Ah, I see.
|
| All times are GMT. The time now is 11:05. |
Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.