query = function to mysqli_query
checkinfo = function to check whether column consist data exist or not.
d_id = department id(primary key for table department)
d_pid = department parent id
我尝试从表中删除行。但在删除那些行之前,我想删除所有使用当前删除行作为其d_pid的行。将有4级结构。
下面,我尝试通过先检查内容来执行命令。如果内容存在,mysql假设首先删除子行。但是如果子行也有子行,则mysql假设在较高行之前将其删除。
for($x1 = checkInfo("d_id","department","WHERE d_pid='$selectedID'");!empty($x1);$count1++){
for($x2 = checkInfo("d_id","department","WHERE d_pid='$x1'");!empty($x2);$count2++){
for($x3 = checkInfo("d_id","department","WHERE d_pid='$x2'");!empty($x3);$count3++){
query($con,"DELETE FROM department WHERE d_id='$x3' OR d_pid='$x3'");
// echo "3</br>";
}
query($con,"DELETE FROM department WHERE d_id='$x2' OR d_pid='$x2'");
// echo "2</br>";
}
query($con,"DELETE FROM department WHERE d_id='$x1' OR d_pid='$x1'");
// echo "1</br>";
}
$sql = "DELETE FROM department WHERE d_id='$selectedID' OR d_pid='$selectedID'";
$result = query($con,$sql);
我遇到了多个错误。还有其他办法吗?