gpt4 book ai didi

php - 我有一个像 Array ( [122] => 2 [123] => 3 [124] => 6 ) 一样动态的数组,我想通过这些数组值从数据库中获取记录

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

我的项目是关于商人和客户的,客户发布他们的工作选择位置,商人可以找到他所在区域的工作,但条件是商人可以添加多个区域所以问题是有一个商人添加了三个位置就像

$locs=Array ( [122] => 2 [123] => 3 [124] => 6 )

我想从数据库中获取这些位置 ID 可用的记录 2,3,6

查询是什么

SELECT j.*, l.location_name, c.customer_name, c.customer_status, s.service_title 
FROM ".TABLE_JOB." AS j
LEFT JOIN ".TABLE_LOCATION." AS l ON (l.location_id=j.location_id)
LEFT JOIN ".TABLE_CUSTOMER." AS c ON (c.customer_id=j.customer_id)
LEFT JOIN ".TABLE_SERVICE." AS s ON (s.service_id=j.service_id)
WHERE j.status='PENDING'
AND c.customer_status='ACTIVATED'
AND j.location_id='".$locs."'

最佳答案

使用implode()函数将数组转换为字符串,然后在mysql查询中in

$locsIds = implode(',', $locs);
select j.*, l.location_name, c.customer_name, c.customer_status, s.service_title from ".TABLE_JOB." as j left join ".TABLE_LOCATION." as l on (l.location_id=j.location_id) left join ".TABLE_CUSTOMER." as c on (c.customer_id=j.customer_id) left join ".TABLE_SERVICE." as s on(s.service_id=j.service_id) where j.status='PENDING' AND c.customer_status='ACTIVATED' and j.location_id IN ({$locsIds})

关于php - 我有一个像 Array ( [122] => 2 [123] => 3 [124] => 6 ) 一样动态的数组,我想通过这些数组值从数据库中获取记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49293322/

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