Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to optimize this query?

Status
Not open for further replies.

kawboy373

Technical User
Feb 15, 2002
2
0
0
US
Code:
$result = mysql_query("
	SELECT 
		*, 
		DATE_FORMAT(call_start,'$dateformat2') as fcall_start 
	FROM 
		call_notes 
	WHERE 
		ticketid='$reviewticketid' 
	ORDER BY 
		$sql_order
		",$dbx);
while ($row = mysql_fetch_array($result)) {
	$noteid = $row[noteid]; 
		$result2 = mysql_query("SELECT note_text FROM call_notes_text WHERE noteid='$noteid'",$dbx);
		$row2 = mysql_fetch_array($result2);
		$note_text = stripslashes($row2[note_text]);
		$note_text = nl2br($note_text);
	$checkuserid = $row[userid]; 
		$result3 = mysql_query("SELECT username, email FROM users WHERE userid='$checkuserid'",$dbx);
		$row3 = mysql_fetch_array($result3);
		$username_notes = $row3[username];
		$email = $row3[email];
	$call_contact = $row[call_contact]; 
		$result3 = mysql_query("SELECT contact FROM facility_contact WHERE contactid='$call_contact'",$dbx);
		$row3 = mysql_fetch_array($result3);
		$contact = $row3[contact];
	$call_elapsed = $row[call_elapsed];

This section hasn't sat well with me ever since I wrote it. It works, but I am interested in combining these 4 queries into one.

My problem is that the 'child' queries are dependant on data pulled out of the first table (call_notes).

Help is greatly appreciated.

Thanks, Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top