Jump to content

Issues with nested while loop


marksie1988

Recommended Posts

Hiu Guys,

 

having a bit ov an issue with this havent had to do anything like this before but here goes below you will see my php code which calls all of the tickets from hd_ticket and then explodes the email address to get the domain.com once it has this i need to select the domain.com from the hd_customers table and update the hd_ticket table company column with the information from the hd_customers table.

 

for some reason when it runs the nested while loop it doesnt loop through all of the results it only displays one on the echo

 

i have also put my table structure to help you out.

 

hd_customers

      id email           company

      1        domain.com      mycompany

 

hd_tickets

ticket_id ticketID dept_id priority_id topic_id staff_id email name subject helptopic phone phone_ext ip_address status source isoverdue isanswered duedate reopened closed lastmessage lastresponse created updated company

 

 

	$sql=	'SELECT * FROM hd_ticket ';
	$result = mysql_query($sql)or die(mysql_error());
		while($row = mysql_fetch_assoc($result)){
			$fromco = explode("@",$row[email]);
			$fromco = $fromco[1];

			$sql=	'SELECT * FROM hd_customer WHERE email="'.$fromco.'"' ;
			$result = mysql_query($sql)or die(mysql_error());
			while($row = mysql_fetch_assoc($result)){
				$company = $row[company] ;

				$sql= 	'UPDATE hd_ticket ticket SET ticket.company='.$company.''; 
				print $sql;
				//mysql_query($sql);
			}
		}


//}

Link to comment
https://forums.phpfreaks.com/topic/201019-issues-with-nested-while-loop/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.