我要在一个网页上时时显示表study里的内容,例如, study里有三条记录,添加一条记录后,想让页面立即刷新到四条记录。
这是view页的内容:
<form id="form1" name="form1" method="post" action="<?php echo $this->editFormAction?>">
<table width="410" border="1" cellspacing="1" cellpadding="0">
<tr>
<td width="90" height="33" align="left" scope="col" class="color">病人症状:</td>
<td width="320" align="left" scope="col" class="color1"><label for="textfield"></label>
<input type="text" name="symptom" id="textfield" /> <span style="color:#FF3300">*</td>
</tr>
<tr>
<td align="left" class="color">诊断日期:</td>
<td align="left" class="color1"><label for="textfield3" ></label>
<input type="text" name="date1" id="textfield3" class="textfield"/>
—
<label for="textfield4"></label>
<input type="text" name="date2" id="textfield4" class="textfield"/>
—
<label for="textfield5"></label>
<input type="text" name="date3" id="textfield5" class="textfield"/><span style="color:#FF3300">*</span></td>
</tr>
<tr>
<td align="left" class="color">诊断医师:</td>
<td align="left" class="color1"><label for="textfield"></label>
<input type="text" name="doctor" id="textfield" /> <span style="color:#FF3300">*</td>
</tr>
<tr>
<td align="left" class="color">诊断结果:</td>
<td align="left" class="color1"><label for="textfield"></label>
<input type="text" name="result" id="textfield" /></td>
</tr>
<tr>
<td align="left" class="color">影像检查:</td>
<td align="left" class="color1"> <input type="text" name="study_description" id="textfield" /> </td>
</tr>
<tr>
<td align="left" class="color">开始时间:</td>
<td align="left" class="color1"> <input type="text" name="study_starttime" id="textfield" /></td>
</tr>
<tr>
<td align="left" class="color">结束时间:</td>
<td align="left" class="color1"> <input type="text" name="study_endtime" id="textfield" /></td>
</tr>
<tr>
<td align="left" class="color">检查医院:</td>
<td align="left" class="color1"><label for="select"></label>
<select name="hospitalID" id="select" class="select">
<?php foreach ($this->rowset as $row):?>
<option value="<?php echo $row['hospitalID'];?>" ><?php echo $row['hospitalname'];?></option>
<?php endforeach;?>
</select></td>
</tr>
<tr>
<input name="patientID" type="hidden" id="id" value="<?php echo $this->row_rsPatient[0]['patientID'];?>">
<td align="left" class="color1"><input type="submit" name="button" id="button" value="提交" /></td>
<td align="left" class="color1"><input type="reset" name="button2" id="button2" value="重置" />
</td></tr>
<tr><td class="color" colspan="2">后面有<span style="color:#FF3300">*</span>号的输入框必须填写
<input type="hidden" name="Study_insert" value="add"></input></td></tr>
</table>
</form>
以下是controller页面内的内容。
$this->view->diag_array=$study->fetchAll($where,$order)->toArray();
$hospital=new hospital();
$this->view->rowset=$hospital->fetchAll()->toArray();
if((isset($_POST["Study_insert"]))&&($_POST["Study_insert"]=="add"))
{
$db=$study->getAdapter();
$row=array(
'symptom'=>GetSQLValueString($_POST['symptom'],"text"),
'diagnosis_date'=>GetSQLValueString($_POST['date1'],"text").'-'.GetSQLValueString($_POST['date2'],"text").'-'.GetSQLValueString($_POST['date3'],"text"),
'doctor'=>GetSQLValueString($_POST['doctor'],"text"),
'result'=>GetSQLValueString($_POST['result'],"text"),
'study_description'=>GetSQLValueString($_POST['study_description'],"text"),
'study_starttime'=>GetSQLValueString($_POST['study_starttime'],"text"),
'study_endtime'=>GetSQLValueString($_POST['study_endtime'],"text"),
'patientID'=>GetSQLValueString($_POST['patientID'],"int"),
'hospitalID'=>$_POST['hospitalID']
);
$this->view->Result1=$study->insert($row);
}
如此方法,添加后,页面并不能马上显示添加后的内容。
应该在<form>之前添加如下几句:
<?php if($this->Result1):?>
<?php echo header(sprintf("refresh:0;url=$this->editFormAction"));?>
<?php endif;?>
即,让页面刷新一下,则,可以显示出刚刚添加的内容。