我有一个php页面,可让我选择日期,然后运行一个查询,执行一些操作,然后使用数据生成临时表。 下一步,我想在页面上显示该数据。但是,连接已关闭,因此数据消失。
如何在删除表之前提取该数据。 我需要删除表,以便我可以使用稍微不同的变量再次运行查询,当我使用regualr表时,我必须重新加载页面,而不是我的一些查询代码删除表。我试着在最后添加一个干净的查询,但我认为发布会让我感到困惑。
...
<?php
//创建表
$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);
//显示表格
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%"> </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);
?>