我向我的 php 网站添加了 onload 函数来提交表单,因为当我最初启动页面时,它没有显示任何表格,我必须按搜索按钮才能加载它。然后就可以正常工作了。但是当我使用 onload 函数时,它会在网络启动时显示表格,但它会不停地重新提交表单。
<body onload="document.search1.submit()">
<form name="search1" id="search1" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
From: <input type="date" id="fdate" name="fdate" value="<?php echo $date_from; ?>" max="00/00/0000" />
Until: <input type="date" id="edate" name="edate" value="<?php echo $date_to; ?>" max="00/00/0000" />
<input type="submit" value="Search">
</form>
这是提交功能。
<?php
if(!empty($_POST['fdate'])) {
$date_from = $_POST['fdate'];
} else {
$date_from = date('Y-m-d',strtotime("-1 days"));
}
if(!empty($_POST['edate'])) {
$date_to = $_POST['edate'];
} else {
$date_to = date('Y-m-d',strtotime("-1 days"));
}
$fdate = $_POST['fdate'];
$edate = $_POST['edate'];
$sql = "select
date_format(entries.Date,'%d/%M/%Y') AS 'Date',
user.Name,user.company AS Company,
user.department AS Department,
min(time_format(entries.Date,'%H:%i:%s')) AS 'Start Time',
IF( max(time_format(entries.Date,'%H:%i:%s'))> min(time_format(entries.Date,'%H:%i:%s')), max(time_format(entries.Date,'%H:%i:%s')),'') AS 'Finish Time',
IF(timediff(max(entries.Date),min(entries.Date)) > '00:00:00', timediff(max(entries.Date),min(entries.Date)), '') AS 'Work Time'
from (entries join user on(entries.emp_id = user.emp_id))
where date_format(entries.Date,'%Y-%m-%d') between '".$fdate."' and '".$edate."'
group by date_format(entries.Date,'%d-%m-%Y'),user.Name
order by Date desc";
?>
繁花如伊