gpt4 book ai didi

php - Laravel 原始查询 - 运行此查询不会选择 id

转载 作者:行者123 更新时间:2023-11-29 10:46:25 24 4
gpt4 key购买 nike

我正在尝试运行此查询,但它找不到 events.id,它实际上返回字符串“events.id”。

 $events = \DB::select(\DB::raw("select 'events.id', `publish_date`, `event_name`, `information`, `latitude`, `longitude`, 111.045 * DEGREES(ACOS(COS(RADIANS(?))
* COS(RADIANS(`latitude`))
* COS(RADIANS(`longitude`) - RADIANS(?))
+ SIN(RADIANS(?))
* SIN(RADIANS(`latitude`))))
AS `distance_in_km`
FROM `events` as `tbl`
where (`publish_date` between ? and ?)
and (`event_name` like ? or `information` like ?)
and (`paid` = 1)
having (`distance_in_km` <= ?)
ORDER BY `distance_in_km` ASC
LIMIT ?,?"), array($lat, $lng, $lat, $date_from, $date_to, $search_term, $search_term, $distance, $page, intval($page)+20));

这是我运行时的响应

"return dd($events)"

array:14 [▼
0 => {#221 ▼
+"events.id": "events.id"
+"publish_date": "2017-05-31"
+"event_name": "asdfasdfas"
+"information": "sdfgsdfgs"
+"latitude": 34.6921597
+"longitude": 5.0225571
+"distance_in_km": 1.4213115203631
}
1 => {#93 ▶}
2 => {#225 ▶}
3 => {#222 ▶}
4 => {#224 ▶}
5 => {#226 ▶}
6 => {#227 ▶}
7 => {#228 ▶}
8 => {#229 ▶}
9 => {#230 ▶}
10 => {#231 ▶}
11 => {#232 ▶}
12 => {#233 ▶}
13 => {#234 ▶}
]

(我需要指定表名,因为实际查询与内部联接有点不同)

最佳答案

您在 events.id 周围使用了错误的引号...

$events = \DB::select(\DB::raw("select `events.id`, `publish_date`,

您选择的是文字“events.id”。

关于php - Laravel 原始查询 - 运行此查询不会选择 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44486112/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com