#48288 [Opn->Bgs]: comment above else statment skips it
| From: | atomkirk at gmail dot com | Date: | Thu, 14 May 2009 23:58:35 +0000 |
| Subject: | #48288 [Opn->Bgs]: comment above else statment skips it | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-2262@lists.php.net to get a copy of this message | ||
ID: 48288
User updated by: atomkirk at gmail dot com
Reported By: atomkirk at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Documentation problem
Operating System: mac osx leopard
PHP Version: Irrelevant
New Comment:
not a php problem. a logical problem.
Previous Comments:
------------------------------------------------------------------------
[2009-05-14 23:51:34] atomkirk at gmail dot com
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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48288&edit=1