php - PHP MySQL 如何检查某个查询是否在数据范围内?

标签 php mysql

我这里有一些问题,

如何检查任一输入是否在数据范围内?第一个 if 语句仅在两个数据具有相同的值两个数据位于数据范围之间

时执行

但如果其中一个数据在范围内,则不会执行

我的问题是,如何检查其中一个输入是否在范围内?

代码如下:

<?php
    $connect      = mysqli_connect("", "root", "", "");
    global $connect;   

    if(isset($_POST['Submit'])){
        $time_out   = $_POST['time_out'];
        $time_enter = $_POST['time_enter'];

        $sql = "SELECT * FROM table";
        $get = mysqli_query($connect,$sql);
        if($get && mysqli_num_rows($get) > 0 ){              
            while($row = mysqli_fetch_assoc($get)){

            $time_out_db    = $row['time_out'];
            $time_enter_db  = $row['time_enter'];

                if(($time_out >= $time_out_db) && ($time_enter <= $time_enter_db))
                {
                    echo "Time is in between";
                }
                else if (){
                    echo "Either one of the time_out or time_enter is in the range";
                }
            }
            mysqli_free_result($get);           
        }else{
            echo "Nothin here !";
        }
    }
?>
<form action="time.php" method="post">  
    <table> 
        <tr>
            <td><i class="fa fa-unlock-alt"></i> </td>
            <td>Time out : </td>
            <td><input type ="text" name="time_out" size="30"></td>
        </tr>
        <tr>
            <td><i class="fa fa-unlock-alt"></i> </td>
            <td>Time enter : </td>
            <td><input type ="text" name="time_enter" size="30"></td>
        </tr>
    </table>    

    <p><input class="btnSuccess" type ="submit" name="Submit" value="Submit"> </p>             
</form>

谢谢。

最佳答案

在第二个 if 中使用 or (||) 条件:

<?php
    $connect      = mysqli_connect("", "root", "", "");
    global $connect;   

    if(isset($_POST['Submit'])){
        $time_out   = $_POST['time_out'];
        $time_enter = $_POST['time_enter'];

        $sql = "SELECT * FROM table";
        $get = mysqli_query($connect,$sql);
        if($get && mysqli_num_rows($get) > 0 ){              
            while($row = mysqli_fetch_assoc($get)){

            $time_out_db    = $row['time_out'];
            $time_enter_db  = $row['time_enter'];

                if(($time_out >= $time_out_db) && ($time_enter <= $time_enter_db))
                {
                    echo "Time is in between";
                }
                else if (($time_out >= $time_out_db) || ($time_enter <= $time_enter_db)){
                    echo "Either one of the time_out or time_enter is in the range";
                }
            }
            mysqli_free_result($get);           
        }else{
            echo "Nothin here !";
        }
    }
?>
<form action="time.php" method="post">  
    <table> 
        <tr>
            <td><i class="fa fa-unlock-alt"></i> </td>
            <td>Time out : </td>
            <td><input type ="text" name="time_out" size="30"></td>
        </tr>
        <tr>
            <td><i class="fa fa-unlock-alt"></i> </td>
            <td>Time enter : </td>
            <td><input type ="text" name="time_enter" size="30"></td>
        </tr>
    </table>    

    <p><input class="btnSuccess" type ="submit" name="Submit" value="Submit"> </p>             
</form>

关于php - PHP MySQL 如何检查某个查询是否在数据范围内?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40606559/

相关文章:

mysql - 为什么自动增量不起作用?

php - 将单选框/复选框更改为对 PHP 编码进行最少更改的下拉框?

php - 创建 PHP 页眉/页脚

php - 无法在 Windows 上的 Xampp 中安装 OAuth 扩展

php - 在 if with 和/或 PHP 语句中正确使用括号

php - CORS 中的 Angular 应用程序丢失 session

mysql - 在 rakudo-star docker 镜像上安装带有 DBIish 的 mysql 的安装要求

mysql - ORDER BY 被忽略,因为表中有用户定义的聚簇索引

python - 在 Raspbian 系统上安装适用于 Python 3.6 的 mysqlclient

php - 使用 where 语句在多列上选择不同的值