$Sql = "
SELECT
dbo.tb_job.nId_job,
dbo.tb_jobtype.cJobtype_name,
tb_building.cBuilding,
actorKong.cKongName AS cActorName,
dbo.tb_lookupmaster.cName AS cStatusName
FROM [dbo].[tb_job]
LEFT JOIN dbo.tb_lookupmaster ON dbo.tb_job.nId_status = dbo.tb_lookupmaster.nId
LEFT JOIN dbo.tb_jobtype ON dbo.tb_job.nId_type = dbo.tb_jobtype.nIdJobtype
LEFT JOIN tb_building ON tb_building.nId_building = tb_job.nId_building
LEFT JOIN dbo.tb_kong AS actorKong ON dbo.tb_job.nId_kongActor = actorKong.nId_kong
WHERE
tb_job.nId_job IS NOT NULL
AND dbo.tb_building.cBuilding LIKE '%$Building[0]%' // <- ตรงนี้ต้องเขียนยังไงครับ ถ้ามีมากกว่า 1 ครับ
";
$Sql = "
SELECT
dbo.tb_job.nId_job,
dbo.tb_jobtype.cJobtype_name,
tb_building.cBuilding,
actorKong.cKongName AS cActorName,
dbo.tb_lookupmaster.cName AS cStatusName
FROM [dbo].[tb_job]
LEFT JOIN dbo.tb_lookupmaster ON dbo.tb_job.nId_status = dbo.tb_lookupmaster.nId
LEFT JOIN dbo.tb_jobtype ON dbo.tb_job.nId_type = dbo.tb_jobtype.nIdJobtype
LEFT JOIN tb_building ON tb_building.nId_building = tb_job.nId_building
LEFT JOIN dbo.tb_kong AS actorKong ON dbo.tb_job.nId_kongActor = actorKong.nId_kong
WHERE
tb_job.nId_job IS NOT NULL";
// ปิดไปก่อน
//AND dbo.tb_building.cBuilding LIKE '%$Building[0]%' // <- ตรงนี้ต้องเขียนยังไงครับ ถ้ามีมากกว่า 1 ครับ
$Sql .= " AND ( ";
// Get array keys
$arrayKeys = array_keys($array);
// Fetch last array key
$lastArrayKey = array_pop($arrayKeys);
foreach($BuildArray as $k => $data) {
$Sql .= "dbo.tb_building.cBuilding LIKE '%$data%'";
if ($k !== $lastArrayKey) {
$Sql .= " OR ";
}
}
$Sql .= ")";