Dan06 Posted January 27, 2009 Share Posted January 27, 2009 I have a php object that performs a series of sql queries and displays the results, the object is supposed to call itself if a particular value is not null. Currently, the object works correctly the first time through the code - the correct information is displayed. But when it comes to calling itself something goes wrong. The page displays the following error: Connection Interrupted. The connection to the server was reset while the page was loading. The network link was interrupted while negotiating a connection. Please try again. Below is the php object code, anyone know where I've gone wrong? Thanks. class messageDetails{ public function displayDetails($msgLinkEnd){ $format = new stringFormat(); $dbconn = new dbConnection(); ... SQL QUERIES ... do{ echo '<div class="displayMsg">' . '<img src="' . $profileImgLoc["profileImage"] . '" width="100px" height="100px" />' . ' ' . $msgInfo["msgDate"] . ' ' . '<a href=message_details.php?msgId=' . $msgInfo["msgId"] . '>' . $msgInfo["msgContent"] . '</a>' . '</div>'; } while ($msgInfo = mysql_fetch_assoc($msgQueryResult)); if ($msgInfo["msgParent"] != NULL || $msgInfo["msgParent"] != "NULL" || $msgInfo["msgParent"] != ""){ $this->displayDetails($msgInfo["msgId"]); } else { return true; } } // end displayDetails function } // end messageDetails class Quote Link to comment https://forums.phpfreaks.com/topic/142680-object-oriented-php-recursion/ Share on other sites More sharing options...
premiso Posted January 27, 2009 Share Posted January 27, 2009 That usually means your recursive loop never exits, it just keeps looping itself. Check your logic and make sure it that it exits and does not just keep going and going and going. Quote Link to comment https://forums.phpfreaks.com/topic/142680-object-oriented-php-recursion/#findComment-747867 Share on other sites More sharing options...
.josh Posted January 27, 2009 Share Posted January 27, 2009 Assuming this: $dbconn = new dbConnection(); establishes a new database connection (like mysql_connect), I would suggest removing that from your recursive function. Not sure what dbConnection() looks like, but if you're not assigning the resource to a variable, that line + recursive function = opening up lots and lots of connections. Quote Link to comment https://forums.phpfreaks.com/topic/142680-object-oriented-php-recursion/#findComment-747875 Share on other sites More sharing options...
printf Posted January 27, 2009 Share Posted January 27, 2009 That function displayDetails will never work the way you have it. Change the do{} to while() so it works the way it should! If you don't understand why then you need to study your logic. If you use do{}, when that loop finishes, $msgInfo will always equal false because there are no more rows. So your if(s) will never get satisfied. Turn error reporting on and you will see all the errors! Quote Link to comment https://forums.phpfreaks.com/topic/142680-object-oriented-php-recursion/#findComment-747878 Share on other sites More sharing options...
Dan06 Posted January 27, 2009 Author Share Posted January 27, 2009 The problem seems to be caused because I assigned mysql_fetch_assoc($msgQueryResult) twice. Below is the entire code. I used the do rather than a while loop because when I used a while loop the image query did not work. class messageDetails{ public function displayDetails($msgLinkEnd){ $format = new stringFormat(); $dbconn = new dbConnection(); $msgParentQuery = sprintf("SELECT message_content.msgParent FROM utilist.message_content WHERE message_content.msgId = %s", $format->formatValue($msgLinkEnd)); $parentQueryResult = mysql_query($msgParentQuery, $dbconn->conn()) or die("Parent Message Query Error: " . $msgParentQuery . mysql_error()); $parentId = mysql_fetch_assoc($parentQueryResult); $messageQuery = sprintf("SELECT msgSender, message_content.msgId, message_content.msgParent, msgDate, msgContent FROM utilist.message_outbox, utilist.message_content WHERE message_content.msgId = %s AND message_outbox.msgId = message_content.msgId", $format->formatValue($parentId["msgParent"])); $msgQueryResult = mysql_query($messageQuery, $dbconn->conn()) or die("Outbox Message Query Error: " . $messageQuery . " " . mysql_error()); $msgFields = mysql_fetch_assoc($msgQueryResult); $membershipIdQuery = sprintf("SELECT membershipId FROM utilist.user_information WHERE userId = %s", $format->formatValue($msgFields["msgSender"])); $memIdQueryResult = mysql_query($membershipIdQuery, $dbconn->conn()) or die("Membership Id Query Error: " . $membershipIdQuery . " " . mysql_error()); $membershipIdValue = mysql_fetch_assoc($memIdQueryResult); $profileImgQuery = sprintf("SELECT profileImage FROM utilist.profile WHERE membershipId = %s", $format->formatValue($membershipIdValue["membershipId"])); $profileImgResult = mysql_query($profileImgQuery, $dbconn->conn()) or die("Profile Image Query Error: " . $profileImgQuery . " " . mysql_error()); $profileImgLoc = mysql_fetch_assoc($profileImgResult); while ($msgInfo = mysql_fetch_assoc($msgQueryResult)){ echo '<div class="displayMsg">' . '<img src="' . $profileImgLoc["profileImage"] . '" width="100px" height="100px" />' . ' ' . $msgInfo["msgDate"] . ' ' . '<a href=message_details.php?msgId=' . $msgInfo["msgId"] . '>' . $msgInfo["msgContent"] . '</a>' . '</div>'; } /* if ($msgInfo["msgParent"] != NULL || $msgInfo["msgParent"] != "NULL" || $msgInfo["msgParent"] != ""){ $this->displayDetails($msgInfo["msgId"]); } else{ return true; } */ } // end displayDetails function } // end messageDetails class Quote Link to comment https://forums.phpfreaks.com/topic/142680-object-oriented-php-recursion/#findComment-747882 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.