我的功能有问题。我请求从数据库中选择,选择是正常的,并且有第二个代码应该price
从结果中获取列的值,但问题是我得到一个错误结果:Trying to get property of non-object
.
我的代码:
$betitem = \DB::table('items')->where('status', 0)->where('price', '>=', 10)->orderByRaw('RAND()')->take(1)->get(); $green_tickets = $betitem->price;
如果写var_dump($betitem[0]); exit;
我收到:
object(stdClass)#584 (13) { ["id"]=> int(548) ["assetid"]=> string(11) "18235855849" ["market_hash_name"]=> string(15) "Staff of Gun-Yu" ["classid"]=> string(231) "-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KW1Zwwo4NUX4oFJZEHLbXK9QlSPcU_phVWSVXvTO2j0IDeXFN_IB1ovbOrLDhp3v7HYylD4OOhkYGbmPm7PrTfnW5I1854hO7-_IH4h0agqh8DJDyiZNnLbAE8M13Q-Ae4wrq7g5Pq7cufnCRm7nZ3tCyPlhSyhx1IabZrjPKaQVqAR_se2_6rU3g" ["price"]=> float(26.4) ["steamid"]=> string(1) "1" ["type"]=> string(4) "card" ["bot"]=> string(1) "1" ["status"]=> int(0) ["created_at"]=> string(19) "2020-02-27 01:47:12" ["updated_at"]=> string(19) "2020-03-14 17:41:25" ["is_withdraw"]=> int(0) ["is_raffling"]=> int(0) }
我如何理解问题的出现是因为结果是在数组中接收的。但是如何修复这个错误并从price
列中获取结果呢?
千万里不及你
慕的地8271018
holdtom