【发布时间】:2018-05-02 02:21:55
【问题描述】:
我目前正在处理一个学校项目,并试图从成功运行的查询中检索值。查询是这样的:
$airportQuery = Airport::where('id', '=', $airport)->get(); //Returns all columns of users selected airportId
我正在尝试检索列“extendedcenterlineLong”和“extendedcenterlineLat”。我通过运行来做到这一点
array[] = $airportQuery->extendedcenterLong;
array[] = $airportQuery->extendedcenterLat;
(该数组也未命名为 array[])当我尝试运行 myQuery 时出现此错误
我无法解决这个问题,我做错了什么? 非常感谢!
编辑:我也有这些查询来获取用户选择的上一行或下一行
$previous = Airport::where('id', '<', $airport)->max('id'); //Returns the previous rows values from users current selected airportId
$next = Airport::where('id', '>', $airport)->min('id'); //Returns the next rows values from users current selected airportId
编辑:我通过$airportQuery->first()->column_name 解决了这个问题。出于某种原因,当我打印出 $airportQuery 时,有两个项目是彼此相同的列信息数组,基本上是一个副本。
【问题讨论】:
-
尝试打印出
$airportQuery->extendedcenterLong以确保您获得价值 -
我试着做 print_r($airportQuery->extendedcenterLong);但我在顶部没有打印。我尝试只打印 $airportQuery 但我是一组正确信息,然后另一个副本打印了相同的信息,这是一个问题吗?
-
可能问题出在
$airport.. 它无法识别变量.. 让我们尝试将其打印出来并确保变量具有/已识别的值 -
我通过调用 $airportQuery->first()->extendedcenterLong 解决了这个问题,谢谢大家的帮助
标签: mysql laravel controller