Page 1 of 1
how to trace back deleted id
Posted: Sat Sep 13, 2008 9:42 pm
by oneyani
hye all...
i want to ask how to trace back deleted id
for example:
(page1)
i have register
company(idcompny)
for each compny have thier own category
(idcategory) and group(idgroup)
(page 2)
i want to use the
compny(idcompny) to add contact person
but the
company can be search only by category
(idactegory) and group(idgroup)
let say
idcategory and idgroup have been deleted(page 1)
so how can i will trace that
compny which doesn't no have any
idcategory and idgroup?in page 2
its is posibble to do this?or any idea to solve this prob...
really need your idea.
thank you in advance

Re: how to trace back deleted id
Posted: Sat Sep 13, 2008 10:19 pm
by josh
innodb lets you cascade delete queries I believe, otherwise you would need to find all the sub items of your record, and recursively see if those sub items have sub items, and issue a delete query for each item you are deleting
Re: how to trace back deleted id
Posted: Sat Sep 13, 2008 10:30 pm
by oneyani
jshpro2 wrote:innodb lets you cascade delete queries I believe, otherwise you would need to find all the sub items of your record, and recursively see if those sub items have sub items, and issue a delete query for each item you are deleting
sorry..i don't get ur explaination..
could u give an example?

Re: how to trace back deleted id
Posted: Sat Sep 13, 2008 10:34 pm
by josh
lets say you have categories and products,
your products table has a relational field called category_id, so in other words each product belongs to 1 category. Categories have multiple products. Then lets say products also have multiple stock levels in an inventory level table, since our products exists at more then one warehouse
so categories have many products, products have many levels of stock levels. In innodb you can tell the database this, by setting up your relational fields. You can then tell the database that if a category is deleted all its products, and inventory level entries should be deleted. In your code you just delete the category and innodb handles the rest. This is called a cascade
Otherwise your code will need to first select all the products, loop through the products and select all the stock levels, then delete all the stock levels, delete all the products and finally delete the category.
Instead of deleting the sub-products you could re-assign them to the default category_id, or give the user a choice of action
http://dev.mysql.com/doc/refman/5.0/en/ ... aints.html
Edit: phpmyadmin also provides a useful GUI for setting up cascade deletes.
Re: how to trace back deleted id
Posted: Sat Sep 13, 2008 10:53 pm
by oneyani
jshpro2 wrote:lets say you have categories and products,
your products table has a relational field called category_id, so in other words each product belongs to 1 category. Categories have multiple products. Then lets say products also have multiple stock levels in an inventory level table, since our products exists at more then one warehouse
so categories have many products, products have many levels of stock levels. In innodb you can tell the database this, by setting up your relational fields. You can then tell the database that if a category is deleted all its products, and inventory level entries should be deleted. In your code you just delete the category and innodb handles the rest. This is called a cascade
Otherwise your code will need to first select all the products, loop through the products and select all the stock levels, then delete all the stock levels, delete all the products and finally delete the category.
Instead of deleting the sub-products you could re-assign them to the default category_id, or give the user a choice of action
http://dev.mysql.com/doc/refman/5.0/en/ ... aints.html
Edit: phpmyadmin also provides a useful GUI for setting up cascade deletes.
ok..thanx for the info..
really appreciate it!
but..i still don't have idea to make it

sorry im new in php..just a beginner

Re: how to trace back deleted id
Posted: Sat Sep 13, 2008 11:35 pm
by Bill H
I think you have what's called an "orphan" situation, which means you have a larger problem. You are allowing something to be deleted (category and group), when something else (company) is linked to it as a dependent item. Sort of letting the parent get killed when the kid is still a baby.
What jshpro2 is saying is that before you allow something to be deleted, you need to be sure that nothing is linked below that thing, otherwise you are leaving that linked thing as an "orphan" and unreachable. So before you allow a category to be deleted you should be sure it has no groups belonging to it and before you allow a group to be deleted you should assure the no companies belong to it.
Re: how to trace back deleted id
Posted: Sat Sep 13, 2008 11:41 pm
by oneyani
Bill H wrote:I think you have what's called an "orphan" situation, which means you have a larger problem. You are allowing something to be deleted (category and group), when something else (company) is linked to it as a dependent item. Sort of letting the parent get killed when the kid is still a baby.
What jshpro2 is saying is that before you allow something to be deleted, you need to be sure that nothing is linked below that thing, otherwise you are leaving that linked thing as an "orphan" and unreachable. So before you allow a category to be deleted you should be sure it has no groups belonging to it and before you allow a group to be deleted you should assure the no companies belong to it.
ok..now im bit more clearer..
so before deleted the category..it should be a pop up menu(warning)
or else the compny colud not saved if there's no category because its a mandatory field..
it is?