简体   繁体   English

如何在选择选项语句中检查“所有”情况

[英]How to check for 'All' cases in select option statement

I have a problem in my code that maybe someone can check and point out the problem.我的代码有问题,也许有人可以检查并指出问题。 I'm creating two webpages in php and I'm requesting variables from one page to another.我在 php 中创建了两个网页,我正在请求从一个页面到另一个页面的变量。 As you see in the photo in my first page I have a drop list of values I successfully grab from a database.正如您在我第一页的照片中看到的,我有一个从数据库中成功抓取的值的下拉列表。 In the second page I want to print a list of matching items which are boats based on the choice the user select from the first page.在第二页中,我想根据用户从第一页中选择的选项打印匹配项的列表,这些项是船。 Now from there I creating a sql query to first check that the user is not selected 'All' or not mixing 'All' with the provided choices.现在,我创建了一个 sql 查询,首先检查用户是否未选择“全部”或未将“全部”与提供的选项混合。 If either is not the case then the database field name is equal to the requested item and echo that to the screen.如果不是这种情况,则数据库字段名称等于请求的项目并将其回显到屏幕上。 In second page I have successfully connected to the database.在第二页中,我已成功连接到数据库。 The problem is when testing my code, the screen is blank which means, my string is faulty.问题是在测试我的代码时,屏幕是空白的,这意味着我的字符串有问题。 Thanks in advance.提前致谢。 Here is my code这是我的代码

From what I can see here you're continuously overwriting the value of sqlStr instead of adding to it.从我在这里看到的情况来看,您一直在覆盖sqlStr的值而不是添加它。

And you're missing $ before sqlStr并且您在sqlStr之前缺少$

Try:尝试:

$sqlStr = "SELECT * FROM boats  Where";

if($boatClass == 'All')
    (
        $sqlStr .= " AND 1=1";
    )
else
{
    'Class' = $boatClass;
}
if($boatMake == 'All')
    (
        $sqlStr .= " AND 1=1";
    )
else
{
    'Make' = $boatMake;
}
if($Year == 'All')
    (
        $sqlStr .= " AND 1=1";
    )
else
{
    'Year' = $Year;
}
if($used == 'All')
    (
        $sqlStr .= " AND 1=1";
    )
else
{
    'UsedOrNew' = $used;
}

A blank page means you have parsing errors.空白页意味着您有解析错误。 If you are working on a dev machine only, you can change the php.ini to display errors.如果您只在开发机器上工作,您可以更改 php.ini 以显示错误。 By default it is off for security reasons.出于安全原因,默认情况下它是关闭的。

Or you can check the error log, it gets populated every time a script with errors in it is run.或者您可以检查错误日志,每次运行有错误的脚本时都会填充它。

To find where your log file is, run a phpinfo script: http://php.net/manual/pt_BR/function.phpinfo.php and check for error_log.要查找日志文件的位置,请运行 phpinfo 脚本: http : //php.net/manual/pt_BR/function.phpinfo.php并检查 error_log。

If it is blank, then default locations for error log file:如果为空,则错误日志文件的默认位置:

linux + nginx is: /var/log/nginx/error.log
linux + apache is: /var/log/apache/error.log
Windows is likely to be in path/to/php/log/error-something.txt

Hope this helps,希望这可以帮助,

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

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