|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-05-14 23:58 UTC] atomkirk at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 03:00:02 2025 UTC |
Description: ------------ if you look at the comment "if this child has no other parents besides this one being deleted" right above the else statement. That comment causes php to skip over the else statement, so both blocks are executed. I moved that comment below the else statment, and it executes only the block its supposed to. In other words, it fixes the problem. I'm no seasoned programmer, but it seems you should be able to place comments there without a problem. Reproduce code: --------------- //otherwise, we are deleting the actual record and need to transfer primary children to a secondary parent $get_direct_decendants = q("SELECT * FROM dayta_records WHERE parent_record = '$record_id'"); while($child = mysql_fetch_assoc($get_direct_decendants)) { $child_id = $child['record_id']; $get_other_parents = q("SELECT * FROM dayta_parents WHERE record_id = '$child_id'"); //if this child has another parent, transfer it into its primary if(mysql_num_rows($get_other_parents)>0) { $parent = mysql_fetch_assoc($get_other_parents); //get another parent and make it the primary parent record $new_parent_id = $parent['parent_id']; $update = q("UPDATE dayta_records SET parent_record = '$new_parent_id' WHERE record_id = '$child_id'"); $delete = q("DELETE FROM dayta_parents WHERE record_id = '$child_id' AND parent_id = '$new_parent_id'"); //if this child has no other parents besides this one being deleted }else{ //if this child has no other parents besides this one being deleted $update = q("UPDATE dayta_records SET parent_record = '0' WHERE record_id = '$child_id'"); //deleteRecord($child_id); } } Expected result: ---------------- should execute only the IF block Actual result: -------------- but because of the comment, it executes both IF and ELSE blocks.