sorry, simply explaing the process is not enough. it is accomplished using recursion:
<?
$myArray=array();
$myArray[]='3';
function findMyChildren($id) {
global $myArray;
$query="SELECT * FROM table WHERE categoryParentId='{$id}'";
$result=mysql_query($query
$num=mysql_num_rows($resul
for ($i=0;$i<$num;$i++){
$cid=mysql_result($result,
$myArray[]=$cid
findMyChildren($cid);
}
}
$q="categoryId='".implode(
$query="DELETE from TABLE WHERE {$q}";
$result=mysql_query($query
?>
I didn't test the code, but it should work. Let me know it it errors on you.
Main Topics
Browse All Topics





by: mattjp88Posted on 2007-06-05 at 18:04:09ID: 19221910
ok, what you need to do, is follow this loop. Suppose you want to delete all children of #3.
"' OR categoryId='",$array)."'";
-have an array with #3 in it
-select all rows with categoryParent=3
-add all those children to the array
-loop through all the selected children and do the same you did with #3
eventually you will reach all the children. Then after that, do something like this:
$q="categoryId='".implode(
$query="DELETE from TABLE WHERE {$q}";
That should do you. If you have any questions about actually coding it, feel free to ask.
-Matt