MySQL temp tables or Calling Stored procedures in CS4
I need to filter a result set by username before performing a LEFT JOIN and including OR IS NULL rows. The SQL works from from the mysqli client, by either creating a temp table using "create temporary table temp_appts select * from..." Or by creating a stored procedure which contains the same "create temp table" statement, then running my LEFT JOIN statement against the temp table.
I have tried both in CS4, it accepts the code in "code view" without errors but the page in a browser loads as a blank or a 500 error in IE. In my experience, this is caused by exiting before reaching the html header.
Is it possible to do either in CS4? Below is the code I am using.
$varU_temp_appts = "-1";
if (isset(<?php $_SESSION['MM_Username'])){
$varU_temp_appts =$_SESSION['MM_Username'];
}
mysql_select_db($database_ess, $ess);
$query_temp_appts = sprintf("CREATE TEMPORARY TABLE temp_appts SELECT * FROM appts WHERE username=%s", /GetSQLValueString($varU_temp_appts, "text"));
$temp_appts = mysql_query($query_temp_appts, $ess) or die(mysql_error());
$row_temp_appts = mysql_fetch_assoc($temp_appts);
$totalRows_temp_appts = mysql_num_rows($temp_appts);
mysql_select_db($database_ess, $ess);
$query_todays_appts = "SELECT * FROM appt_tm LEFT JOIN (temp_appts) ON appt_tm.appt_time=temp_appts.appt_hr WHERE(appt_date=CURDATE() OR appt_date IS NULL)";
$todays_appts = mysql_query($query_todays_appts, $ess) or die(mysql_error());
$row_todays_appts = mysql_fetch_assoc($todays_appts);
$totalRows_todays_appts = mysql_num_rows($todays_appts);
Any help is appreciated!
