Php 和拉威尔4号的接线员

Php 和拉威尔4号的接线员,php,laravel,laravel-4,Php,Laravel,Laravel 4,我试图获取3个值=2个select forms和1个from date form,并将其与数据库中的值进行比较(如果相等),但每当我尝试使用laravel中的and运算符比较其中的3个值时,它都不会给我任何详细信息。如何正确比较它们 OnewayflightController.php 数据库: id-1 目的地澳大利亚 来自日本的命运 出发日期:01-2-14 onewayflight.blade.php 更新 我变了 ->其中'destinationfrom','=',$search3 到

我试图获取3个值=2个select forms和1个from date form,并将其与数据库中的值进行比较(如果相等),但每当我尝试使用laravel中的and运算符比较其中的3个值时,它都不会给我任何详细信息。如何正确比较它们

OnewayflightController.php

数据库:

id-1

目的地澳大利亚

来自日本的命运

出发日期:01-2-14

onewayflight.blade.php

更新

我变了

->其中'destinationfrom','=',$search3

->其中“出发”,“=”,$search3

但还是没有结果

您的第三个位置应该是搜索出发点,而不是第二次的目的地。

问题

->where('destinationfrom','=',$search3)
更新您的

->where('departure','=',$search3)

我想这样行。

需要向您更新第三个条件。您正在将destinationfrom value进行两次比较

我认为您正在寻找一个集合,并且认为这不是一个结果

尝试:

这将转储使用输入找到的所有行。只想要一个结果?改变->获得;失败或失败。然后,您可以在不使用foreach的情况下转储$results

或者子查询是解决方案

$results = DB::table('oneways')
               ->where('destinationto', '=', $search1)
               ->where('destinationfrom', '=', $search2)
               ->where(function($query) {
                        return $query->where('departure', '=', $search3)
                })
        ->get();
你只想得到一个结果吗?也许这样更好:

$results = DB::table('oneways')
               ->where('destinationto', '=', $search1)
               ->where('destinationfrom', '=', $search2)
               ->where(function($query) {
                        return $query->where('departure', '=', $search3)
                })
        ->firstOrFail();
这将给您一个结果,而不是一个集合

如果这不起作用,您可以尝试转储输入以检查其是否正确填写:

public function onewayflightresults()
{
   dd(Input::all());
   // Rest of the code
}
如果输入中的值::all;如果与数据库中的值完全相同,则查询应给出结果。如果没有,请尝试以下步骤以进一步调试:

dd(DB::table('oneways')->where('id', '=', 1)->first());

我从没见过那个打字错误。已更新但仍然没有返回任何内容。已更新但仍然没有结果请确保$search变量获得所需的值。如果该值无效,则无法获得正确的输出。只需将您的数据库值与搜索值进行比较,就可以得到var_dump的结果,它显示了所需的结果。但是当我尝试比较这三个变量时,它不会显示结果。你的意思是说你的查询得到了你所需要的结果?当我尝试分别对它们进行var_转储时,但如果我尝试对$results进行var_转储,它不会显示任何结果。请您提供一些更多的信息,如您的数据与数据库记录和搜索值的相似性,以便我们能够了解。谢谢您的回复,先生。我尝试过执行您建议的代码,但它给了我未定义的变量:search3。另外,我已经将第二个$search1更改为$search3您在将搜索1更改为搜索3后得到了未定义的变量?
$results = DB::table('oneways')
               ->where('destinationto', '=', $search1)
               ->where('destinationfrom', '=', $search2)
               ->where(function($query) {
                        return $query->where('departure', '=', $search3)
                })
        ->firstOrFail();
public function onewayflightresults()
{
   dd(Input::all());
   // Rest of the code
}
dd(DB::table('oneways')->where('id', '=', 1)->first());