Jump to content

Not returning result from 2nd time in loop


tanveer

Recommended Posts

Hi,

I am facing a weird problem..  table `getReceiverID` was supposed to return all the empid values by running the query which it's not doing. It works only for the first time and after that the output of mysql_num_rows() gets zero. But it shouldn't be.. I am stuck .. What I am doing wrong ?

 

Thank you.

 

public function tblRcptInfo($rtype, $hValue ){
	/*
	 * Fetch Last mail_id Value from `message` table
	 */
	$mail_id			= PopulateTables::findLastMailId();


	$headerValue	= explode(",", $hValue);

	foreach ($headerValue as $value){

		$receiverID	=	PopulateTables::getReceiverID($value);

	}

}
	public function getReceiverID ($rEmail){

	$dbConnect 	= new DBConnect();
	$dbConnect->Connection("localhost", "dbanme", "uname", "");

	$findIdQuery	= "SELECT emp_id FROM emplist WHERE emp_addr='$rEmail'";

	$resultQuery	= mysql_query($findIdQuery) or die ("Error: Select Query Failed for emp_list Table ");

	$countRows = mysql_num_rows($resultQuery);
	echo "rows ret:".$countRows;

	$rID		   	= mysql_fetch_array($resultQuery);

			return $rID[0];

	}

Link to comment
Share on other sites

Hi,

I am facing a weird problem..  table `getReceiverID` was supposed to return all the empid values by running the query which it's not doing. It works only for the first time and after that the output of mysql_num_rows() gets zero. But it shouldn't be.. I am stuck .. What I am doing wrong ?

 

Thank you.

 

public function tblRcptInfo($rtype, $hValue ){
	/*
	 * Fetch Last mail_id Value from `message` table
	 */
	$mail_id			= PopulateTables::findLastMailId();


	$headerValue	= explode(",", $hValue);

	foreach ($headerValue as $value){

		$receiverID	=	PopulateTables::getReceiverID($value);

	}

}
	public function getReceiverID ($rEmail){

	$dbConnect 	= new DBConnect();
	$dbConnect->Connection("localhost", "dbanme", "uname", "");

	$findIdQuery	= "SELECT emp_id FROM emplist WHERE emp_addr='$rEmail'";

	$resultQuery	= mysql_query($findIdQuery) or die ("Error: Select Query Failed for emp_list Table ");

	$countRows = mysql_num_rows($resultQuery);
	echo "rows ret:".$countRows;

	$rID		   	= mysql_fetch_array($resultQuery);

			return $rID[0];

	}

 

You need a while loop:

 

http://www.php.net/manual/en/control-structures.while.php

Link to comment
Share on other sites

Thanks for the reply.

I changed to while loop but still same.

 


public function tblRcptInfo($rtype, $hValue ){
	/*
	 * Fetch Last mail_id Value from `message` table
	 */
	$mail_id			 = PopulateTables::findLastMailId();


	$headerValue	= explode(",", $hValue);


	$i = 0 ;
while ($i < count($headerValue)){


		$receiverID	=	PopulateTables::getReceiverID($headerValue[$i]);

		PopulateTables::populateRcptInfo( $rtype, $receiverID, $mail_id );

	$i ++;

}

}
	public function getReceiverID ($rEmail){

	$dbConnect 	= new DBConnect();
	$dbConnect->Connection("localhost", "dbname", "uname", "");

	$findIdQuery		= "SELECT emp_id FROM emplist WHERE emp_addr='$rEmail'";

	$resultQuery		= mysql_query($findIdQuery) or die ("Error: Select Query Failed for emp_list Table ");
	echo "QUery:".$findIdQuery;

	$countRows = mysql_num_rows($resultQuery);


	$rID		    = mysql_fetch_array($resultQuery);

			return $rID[0];

	}


	public function populateRcptInfo ( $rtype, $receiverID, $mail_id ){

		$dbConnect 	= new DBConnect();
		$dbConnect->Connection("localhost", "dbname", "uname", "");


		 $insertQuery= "INSERT INTO rcptinfo (reply_type, receiver_id, mail_id)
										VALUES ('$rtype', $receiverID, $mail_id )";
			echo $insertQuery;

		 mysql_query($insertQuery) or die("Error: Insert Query Failed for `RcptInfo` Table");


	}

 

here is the output of query where it's showing in 2nd time it's not getting the result ...

QUery:SELECT emp_id FROM emplist WHERE emp_addr='h..lewis@enron.com'
INSERT INTO rcptinfo (reply_type, receiver_id, mail_id) VALUES ('TO', 2, 1 )
QUery:SELECT emp_id FROM emplist WHERE emp_addr=' dutch.quigley@enron.com'
INSERT INTO rcptinfo (reply_type, receiver_id, mail_id) VALUES ('TO', , 1 ) Error: Insert Query Failed for `RcptInfo` Table

Link to comment
Share on other sites

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.