操作数不正常。 Laravel

时间:2017-01-30 06:16:17

标签: php mysql laravel

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

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

但它正在返回空值。我桌上的价格大于500.

奇怪的是当我查询以下

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

它正在返回值。这不应该发生,因为我的价格不低于500.任何人都可以帮助我吗?

I have attached values of price of my table

2 个答案:

答案 0 :(得分:2)

在你的任何地方找不到任何问题。 要检索价格> 500的所有车辆的清单,您必须使用:

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

要检索价格> 500的一辆车,您必须使用:

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

答案 1 :(得分:0)

试试这个

vehicles::where('price','>',500)->orderBy('price','ASC')->first();

它会给你第一行有价格&gt; 500。 将字符串类型更改为int(11)。

  

它在少于500个查询中工作,因为它将以整数转换您的字符串价格,并且字符串的整数为0.然后当您运行&lt; 500询问然后是。零显然小于500。