Re: How to Delete the parent node, and child nodes/leafs for a db/tbl in php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2009-10-16 at 08:34 -0700, bruce wrote:

> Hi.
> 
> I've got a situation where I have a couple of tables. The relationship
> between the tables is one of parent/child. I'm trying to figure out the best
> approach to being able to delete the associated children in the child tbls,
> of a given parentID in the parentTBL...
> 
> I've checked into various sites/articles on the 'net.. but i'm not sure how
> best to accomplish this...
> 
> I'm using php as the interface language to the test tbls..
> 
> Any pointers/articles/test code (code/schema) would be helpful...
> 
> Thanks
> 
> 
> 


Well if the tables truly have a relationship, then no PHP is necessary.

I assume that to connect the 'parent' row with the 'children' rows of
the secondary table you've used an identifying field. For example:

users table:
user_id
forename
surname

emails table:
email_id
user_id
email_address

So in the above example, a user on the users table could have several
entries in the emails table for each email address they have.
emails.user_id will match up users.user_id so you can run a query like

DELETE FROM emails WHERE user_id=id

Is this any help?


Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux