gpt4 book ai didi

PHP 使用日期范围显示数据

转载 作者:行者123 更新时间:2023-11-30 23:31:24 25 4
gpt4 key购买 nike

在这里,我得到了答案。

我只是将 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'";
}
}

现在没有问题代码可以顺利运行了。感谢您的帮助 friend 。感谢您的建议和意见。


我的以下代码有问题:

  1. 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 online 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>
  1. 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>
    ";

    ?>

有人可以帮助我吗?感谢您的帮助。

最佳答案

确定 ot_date 的数据类型是否为 datetime ?也许你使用了 varchar

关于PHP 使用日期范围显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10427551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com