Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/142680-object-oriented-php-recursion/
Share on other sites

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.

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!

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.