我试图转换这两个现有的选择查询:
$expiredCheck = "
SELECT
sku_id,
dealer_id,
expire_date
FROM dealerplacetest p
INNER JOIN skus s
ON p.sku_id = s.id
WHERE p.dealer_id = :DEALER
AND s.build = :build
AND s.cov = :cov
AND s.col = :col
AND p.expire_date <= date_add(convert(:ship,date), interval 7 day)
";
$validCheck = "
SELECT
sku_id,
dealer_id,
expire_date
FROM dealerplacetest p
INNER JOIN skus s
ON p.sku_id = s.id
WHERE p.dealer_id = :DEALER
AND s.build = :build
AND s.cov = :cov
AND s.col = :col
AND p.expire_date > date_add(convert(:ship,date), interval 7 day)
";
像这样的一般选择:
$expiredCheck = "
SELECT
sku_id,
dealer_id,
expire_date
FROM dealerplacetest p
INNER JOIN skus s
ON p.sku_id = s.id
WHERE p.dealer_id = :DEALER
AND s.build = :build
AND s.cov = :cov
AND s.col = :col
";
然后使用我现有的绑定参数($ values2)来制定if语句,该语句将替换先前存在的到期日期检查。基本上我已经从查询中获取了之前的2个到期日期检查,并将它们插入到if语句中,但它没有通过&#39; 7&#39;在我的日间隔。我觉得这里可能有不同的语法标准,但我似乎无法找到合适的解决方案。
我试图为第一次检查创建$ count3变量,为第二次检查创建$ count4变量。 这是params和if声明:
$values2 = [
":DEALER" => $row2["DEALER"],
":build" => $row2["build"],
":cov" => $row2["cov"],
":col" => $row2["col"],
":ship" => $row2["ship"],
];
$existingRslt = $checkExisting->execute($values2);
while($existingRow = $checkExisting->fetch(PDO::FETCH_ASSOC)){
if($existingRow["expire_date"] <= date_add(convert(":ship",date), interval 7 day){
$count3 = $checkExisting->fetch(PDO::FETCH_ASSOC);
}elseif($existingRow["expire_date"] > date_add(convert(":ship",date), interval 7 day)){
$count4 = $checkExisting->fetch(PDO::FETCH_ASSOC);
}
}
我只是想尽可能地整合SELECT查询。我做错了什么?
答案 0 :(得分:0)
你不能在PHP中使用convert(“:ship”,date),所以使用类似这样的东西date_add($date,date_interval_create_from_date_string("7 days"));