简体   繁体   English

PHP查询到MYSQL,在WHERE中没有可用的ELSE选项

[英]PHP query to MYSQL with no working ELSE options in WHERE

My script is prepared for the checkbox answers, but I would also want to if none of the checkbox with instruktor or with instruktor_poczatkowy etc. to select whole column and in case of select some options to do only this options. 我的脚本已经为复选框的答案做好了准备,但是我也希望是否没有使用instruktor或instruktor_poczatkowy等复选框来选择整个列,并且在选择某些选项的情况下仅选择此选项。

$dbr = dbq("SELECT * FROM `table` WHERE instruktor LIKE '%' OR instruktor in ('$instruktor1', '$instruktor2', '$instruktor3', '$instruktor4',
                           '$instruktor5', '$instruktor6', '$instruktor7', '$instruktor8', '$instruktor9', '$instruktor10', '$instruktor11', '$instruktor12')
                            AND instruktor_poczatkowy in ('$instruktor_poczatkowy1', '$instruktor_poczatkowy2',
                           '$instruktor_poczatkowy3', '$instruktor_poczatkowy4', '$instruktor_poczatkowy5', '$instruktor_poczatkowy6',
                           '$instruktor_poczatkowy7', '$instruktor_poczatkowy8', '$instruktor_poczatkowy9', '$instruktor_poczatkowy10',
                           '$instruktor_poczatkowy11', '$instruktor_poczatkowy12') AND lokalizacja in ('$lokalizacja1','$lokalizacja2', '$lokalizacja3',  '$lokalizacja4', '$lokalizacja5')
                            AND status in ('$status1', '$status2', '$status3', '$status4')
AND chce_mail like '$chce_mail2' AND klub like '$klub2' order by nazwisko");

I would like it to work like: 我希望它像这样工作:

        $dbr = dbq("SELECT * FROM `table` WHERE instruktor LIKE '%' OR instruktor in ('$instruktor1', '$instruktor2', '$instruktor3', '$instruktor4',
                           '$instruktor5', '$instruktor6', '$instruktor7', '$instruktor8', '$instruktor9', '$instruktor10', '$instruktor11', '$instruktor12')
                           ELSE instruktor = % AND instruktor_poczatkowy in ('$instruktor_poczatkowy1', '$instruktor_poczatkowy2',
                           '$instruktor_poczatkowy3', '$instruktor_poczatkowy4', '$instruktor_poczatkowy5', '$instruktor_poczatkowy6',
                           '$instruktor_poczatkowy7', '$instruktor_poczatkowy8', '$instruktor_poczatkowy9', '$instruktor_poczatkowy10',
                           '$instruktor_poczatkowy11', '$instruktor_poczatkowy12') ELSE instruktor_poczatkowy = % AND lokalizacja in ('$lokalizacja1','$lokalizacja2', '$lokalizacja3',  '$lokalizacja4', '$lokalizacja5')
                           ELSE lokalizacja = % AND status in ('$status1', '$status2', '$status3', '$status4') ELSE status = %
AND chce_mail like '$chce_mail2' AND klub like '$klub2' order by nazwisko");

but don't no the way to do it... can someone give me an advice? 但不是没有办法...有人可以给我建议吗?

LIKE '%'

This means that your value can be anything, which is always true (except when your value is null I suppose) 这意味着您的值可以是任何东西,始终为真(我想除非您的值为null)

LIKE 'foo'

This means your value is exactly 'foo' 这意味着您的值正好是“ foo”

LIKE '%foo'

This means that your value ends with 'foo' 这意味着您的值以'foo'结尾

LIKE 'foo%'

This means that your value starts with 'foo' 这意味着您的值以'foo'开头

LIKE '%foo%'

This means that your value contains 'foo' 这意味着您的值包含“ foo”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM