tanveer Posted June 5, 2011 Share Posted June 5, 2011 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 https://forums.phpfreaks.com/topic/238460-not-returning-result-from-2nd-time-in-loop/ Share on other sites More sharing options...
HDFilmMaker2112 Posted June 5, 2011 Share Posted June 5, 2011 Quote 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 https://forums.phpfreaks.com/topic/238460-not-returning-result-from-2nd-time-in-loop/#findComment-1225369 Share on other sites More sharing options...
tanveer Posted June 5, 2011 Author Share Posted June 5, 2011 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 https://forums.phpfreaks.com/topic/238460-not-returning-result-from-2nd-time-in-loop/#findComment-1225395 Share on other sites More sharing options...
tanveer Posted June 5, 2011 Author Share Posted June 5, 2011 Found it ... in Email I forgot to sanitize the variable .. Now after removing spaces from email it's working as there was a space in front an email .. Thanks all. Link to comment https://forums.phpfreaks.com/topic/238460-not-returning-result-from-2nd-time-in-loop/#findComment-1225396 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.