Php 操作数工作不正常。拉维尔

Php 操作数工作不正常。拉维尔,php,mysql,laravel,Php,Mysql,Laravel,我试图从价格高于500美元的表中获取价值。我尝试了以下语法: $vehicles=vehicles::where('price','>',500)->get()->first(); 但它返回的是空值。我桌上的价格超过500英镑 奇怪的是,当我询问以下问题时 $vehicles=vehicles::where('price','<',500)->get()->first(); $vehicles=vehicles::where('price'),在您的whe

我试图从价格高于500美元的表中获取价值。我尝试了以下语法:

$vehicles=vehicles::where('price','>',500)->get()->first();
但它返回的是空值。我桌上的价格超过500英镑

奇怪的是,当我询问以下问题时

$vehicles=vehicles::where('price','<',500)->get()->first();

$vehicles=vehicles::where('price'),在您的where条件下未发现任何问题。
要检索价格>500的所有车辆的列表,您必须使用:

$vehicles = vehicles::where(convert(integer, price),'>',500)->get();
$vehicles=vehicles::where(convert(integer, price),'>',500)->first();
要检索一辆价格>500的车辆,您必须使用:

$vehicles = vehicles::where(convert(integer, price),'>',500)->get();
$vehicles=vehicles::where(convert(integer, price),'>',500)->first();
试试这个

vehicles::where('price','>',500)->orderBy('price','ASC')->first();
它将为您提供价格>500的第一行。 将字符串类型更改为int(11)

它在小于500的查询中工作,因为它将以整数形式转换字符串价格,字符串的整数为0。然后,当您运行<500查询时,则为是。0显然小于500


您是否也检查过mysql查询。例如,为您的语句打印一次mysql查询。在这种情况下,请使用DB::enableQueryLog();获取查询并在mysql终端中启动,然后检查happens@jyotimishra当我在mysql中从
vehicles`WHERE
price
>500`中选择*时,它返回的值是必需的。你能检查一下
vehicles::WHERE('price','>',500)->get();
vehicles::WHERE('price','>',500)->first();
@PaladiN仍然返回空值。price字段的数据类型是什么?@AnonIts string.@mithabove answer对于int/float字段类型将正确工作使您的数据类型为integer int(11)。那么,当我使用vehicles::where时,它为什么工作('price','Ya)这会起作用,因为它会将字符串价格转换为整数,字符串的整数为0。然后当您运行<500查询时,则为是。0显然小于500。