在显示数据之前删除临时表

I have a php page that lets me select dates and then run a query that does a few things and then makes a temp table with the data. NEXT, I want to display that data on the page. However, the connection is closed so the data is gone.

How can I extract that data before the tables are removed. I need the tables removed so that I can run the query again with slightly different variables, when I use regualr tables I have to reload the page than some of my query code removes the table. I tried adding a clean query at the end, but I think the posting, messes me up there.

....

<?php

//create the table

$query   = "Drop TABLE if exists temp_pers;";
$query  .= "CREATE temp table temp_pers (seqid integer, Name character(90));";
$query  .= "INSERT INTO temp_pers (seqid, Name)
SELECT per_id, CONCAT('<a href=PersonView.php?PersonID=',per_ID,'>',per_FirstName,' ', per_LastName,'</a>')
    FROM person_per
    WHERE per_id in 
        (SELECT DISTINCT person_id 
            FROM event_attend, events_event
            WHERE events_event.event_type = $group_id and
            date(checkin_date) >= '$dStartDate' and
            date(checkin_date) <= '$dEndDate' and
            event_attend.event_id = events_event.event_id)
ORDER by per_LastName, per_FirstName
;";

#Dates Query
$query  .= "Drop TABLE if exists temp_dates ;";
$query  .= "CREATE temp table temp_dates (meet_date date);";
$query  .= "INSERT INTO temp_dates (meet_date)
SELECT DISTINCT date(event_start)
    FROM event_attend, events_event
    WHERE events_event.event_type = $group_id and
    date(checkin_date) >= '$dStartDate' and
    date(checkin_date) <= '$dEndDate' and
    event_attend.event_id = events_event.event_id
        ORDER BY 1;";
#Final query
$query  .= "Drop TABLE if exists pers_dates;";
$query  .= "CREATE temp table pers_dates (pers_id integer, pers_name character(90), pers_date date, pers_date_attend_ind character(1) NOT NULL default' ');";
$query  .= "INSERT INTO pers_dates(pers_id, pers_name, pers_date)
SELECT temp_pers.seqid, temp_pers.name, temp_dates.meet_date
FROM temp_pers, temp_dates
Where 1=1;";
#update the "y"
$query  .= "UPDATE pers_dates SET pers_date_attend_ind = 'Yes' 
            WHERE EXISTS (SELECT person_id, checkin_date From event_attend, events_event 
            WHERE events_event.event_type= $group_id and pers_id = person_id 
            and pers_date = date(checkin_date) 
            and event_attend.event_id = events_event.event_id);";






mysqli_multi_query($dbc, $query);

//display the table

if(isset($_POST['AttendanceSubmit'])){ // button name

    $query2 = mysql_query("SELECT pers_id , pers_name, pers_date, pers_date_attend_ind FROM pers_dates") or die(mysql_error());
    while($row = mysql_fetch_array($query2)) $rows[] = $row;
    foreach($rows as $key => $value)
    {
        $array[$value['pers_id']]['name'] = $value['pers_name'];
        $array[$value['pers_id']]['dates'][$value['pers_date']] = $value['pers_date_attend_ind'];
    }

    //$rowColor = "brown";
    function generate_table($array)
    {
        $html = '';
        foreach($array as $key => $value)
        {
            $html .= '<table border="1" width="100%" cellpadding="9">'; // start table inside the loop. It will looks better due to each member may have different number of date count.
            $html .= '<tr bgcolor="#F3E2A9">';
            $html .= '<td width="10%">&nbsp;</td>';
            foreach($value['dates'] as $k => $v)
            {
                //Date of meeting
                $html .= '<td>' .' '. $k .' '. '</td>';
            }
            $html .= '</tr>';
            $html .= '<tr>';
            //Person name
            $html .= '<td align="center">' . $value['name'] . '</td>';
            foreach($value['dates'] as $v)
            {
                //attendance indicator
                $html .= '<td align="center">' . $v .' ' . '</td>';
            }
            $html .= '</tr>';
            $html .= '</table>';
        }
        return $html;
    }

    echo generate_table($array);


$clean="Drop TABLE temp_pers, temp_dates, pers_dates;";
mysqli_query($dbc,$clean);      


?>