Select & Inner Join Question

From: Date: Mon, 06 Aug 2001 14:33:43 +0000
Subject: Select & Inner Join Question
Groups: php.db 
Request: Send a blank email to php-db+get-11093@lists.php.net to get a copy of this message
I'm trying to display a summary list of calls with one attribute being CallType. I have CallType and CallTypeID defined in a table name calltypes. The problem I am having is taking the output of CallID defined in calls and having the script match the CallTypeID to the CallType. If I run the display_calltype_sql query in MySQL client and set the CallID to a known integer (set by auto_increment) then I can do what I am trying to do. I guess the problem comes down to getting the $CallID out of the calls table and inserting the value into the second SQL query. I thought my queries did this, but I must be mistaken. Any suggestions? $display_calls_sql = "SELECT CallID,CallDateTime,CallSubject,CallStatus FROM calls WHERE ContactID = $ContactID"; $display_calltype_sql = "SELECT CallType FROM calltypes INNER JOIN calls ON calltypes.CallTypeID = calls.CallTypeID WHERE CallID = '$CallID' "; $display_calls_result = @mysql_query($display_calls_sql,$connection) or die(mysql_error()); $display_calltype_result = @mysql_query ($display_calltype_sql, $connection) or die (mysql_error()); while (list ($CallID, $CallDateTime, $CallSubject, $CallStatus) = mysql_fetch_row($display_calls_result)){ print ("<tr>\n". "<td width=\"21\" height=\"24\">&nbsp;</td>\n". "<td align=\"center\">$CallID</td>\n". "<td width=\"17\">&nbsp;</td>\n". "<td width=\"75\" valign=\"top\">$CallType</td>\n". "<td width=\"26\">&nbsp;</td>\n". "<td>$CallDateTime</td>\n". "<td width=\"19\">&nbsp;</td>\n". "<td><a href=\"display_call.php?ContactID=$ContactID\">$CallSubject</a></td>\n". "<td width=\"25\">&nbsp;</td>\n". "<td>$CallStatus</td>\n". "<td width=\"30\">&nbsp;</td>\n". "</tr>\n"); } ?>

« previous php.db (#11093) next »