来了,我有答案了。
我只是将 track_reports.php 更改为:
if (isset($_POST['chkOtdate']))
{
$date_from = $_POST['date_from'];
$date_to = $_POST['date_to'];
if (empty($bagianWhere))
{
$bagianWhere .= "ot_date between '$date_from' and '$date_to'";
}
else
{
$bagianWhere .= " AND ot_date between '$date_from' and '$date_to'";
}
}
现在没有问题代码可以顺利运行了。感谢各位朋友的帮助。感谢您的建议和意见。
我的代码有问题:
- view_report.php
我们可以根据badge_id、employee_name 和ot_date(带范围)查看报告。当我尝试使用badge_id 和employee_name 发现没有问题时,数据显示。但是当我尝试使用日期范围查找时,发现错误。错误是:: mysql_fetch_array() expects parameter 1 to be resource, boolean given in on line WarningC:\xampp\htdocs\siix_dev\overtime\track_reports.php327
<form method="post" action="track_reports.php" name="form">
<table id="mytable">
<tr>
<td>
<input type="checkbox" name="chkBadge" onClick="apply(this.checked, 'textBox')"> <font class="category">Badge ID</font>
</td>
<td>
<input id="textBox" class="text sign" type="text" name="badge_id">
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="chkEmp" onClick="apply(this.checked, 'textBox2')"> <font class="category">Employee Name</font>
</td>
<td>
<input id="textBox2" class="text sign" type="text" name="employee_name">
</td>
</tr>
<tr>
<td>
<input id="myCheckBox" type="checkbox" name="chkOtdate" onClick="apply(this.checked, 'textBox3')" onChange="apply(this.checked, 'textBox4')"> <font class="category">OT Date</font>
</td>
<td>
<font class="category">From</font> <input id="textBox3" class="text sign" type="text" name="date_from" ><font class="category"> To</font> <input id="textBox4" class="text sign" type="text" name="date_to" >
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
</form>
track_reports.php
$bagianWhere = ""; if (isset($_POST['chkBadge'])) { $badge_id = $_POST['badge_id']; if (empty($bagianWhere)) { $bagianWhere .= "badge_id = '$badge_id'"; } } if (isset($_POST['chkEmp'])) { $employee_name = $_POST['employee_name']; if (empty($bagianWhere)) { $bagianWhere .= "employee_name LIKE '$employee_name'"; } else { $bagianWhere .= " AND employee_name LIKE '$employee_name'"; } } if (isset($_POST['chkOtdate'])) { $date_from = $_POST['date_from']; $date_to = $_POST['date_to']; $query=mysql_query("select badge_id, employee_name from t_submissions where ot_date between '$date_from' and '$date_to'"); while($row=mysql_fetch_array($query)){ echo $row['badge_id']; echo $row['employee_name']; } } $query = "SELECT * FROM t_submissions WHERE ".$bagianWhere; $hasil = mysql_query($query); echo " <div id='main' class='wrapper'> <div class='content-area'> <table cellspacing='0' class='font'>"; echo "<tr><th class='th'>Badge ID</th><th class='th'>Employee Name</th><th class='th'>OT Date</th><th class='th'>Department</th><th class='th'>OT From</th><th class='th'>OT To</th><th class='th'>Remarks</th><th class='th'>Submissions By</th><th class='th'>Acknowledged By</th><th class='th'>Approved By</th></tr>"; while ($data = mysql_fetch_array($hasil)) { echo "<tr><td class='td'>".$data['badge_id']."</td><td class='td'>".$data['employee_name']."</td><td class='td'>".$data['ot_date']."</td><td class='td'>".$data['dept_name']."</td><td class='td'>".$data['ot_from']."</td><td class='td'>".$data['ot_to']."</td><td class='td'>".$data['remarks']."</td><td class='td'>".$data['submission_by']."</td></tr>"; } echo "</table> <br> <input type='button' VALUE='Back' onClick='history.go(-1);return true;'> </div> </div> "; ?>
有人可以帮助我吗?感谢您的帮助。