在SELECT语句中组合AND和OR条件

时间:2018-07-07 18:11:59

标签: php mysql

我尝试将ANDOR语法与SELECT组合使用,但不会显示数据。

$cel可以是数字或空,$ruta$jornada可以分配

$query = mysqli_query($con, 
    "SELECT 
        *
    FROM
        registros_tty651
    WHERE
        (cel = '$cel' OR cel = '')
            AND ruta = '$ruta'
            AND jornada = '$jornada'
    ORDER BY fecha_r DESC;");

1 个答案:

答案 0 :(得分:1)

尝试

$query = mysqli_query($con, 
"SELECT 
    *
FROM
    registros_tty651
WHERE
    (cel = '$cel' OR cel IS NULL)
        AND (ruta = '$ruta'
        AND jornada = '$jornada')
ORDER BY fecha_r DESC;");