$date1 = $_POST['dateStart'];
$date2 = $_POST['dateEnd'];
$txtKeyword = $_POST['txtKeyword'];
$stmt = $conn->prepare("SELECT TOP 500 * FROM SOHD LEFT JOIN EMCust ON EMCust.CustID=SOHD.CustID WHERE
EmpID = $empid AND DocuStatus = 'N' AND SOHD.DocuDate BETWEEN '$date1' AND '$date2' OR DocuNo LIKE '%$txtKeyword%' ORDER BY SOID DESC");
$stmt = $conn->prepare("SELECT TOP 500 * FROM SOHD LEFT JOIN EMCust ON EMCust.CustID=SOHD.CustID WHERE
EmpID = $empid AND DocuStatus = 'N' AND (SOHD.DocuDate BETWEEN '$date1' AND '$date2') AND (DocuNo LIKE '%$txtKeyword%') ORDER BY SOID DESC");
ถ้าใช้ AND สามารถค้นได้ครับ แต่ทีนี้ผมอยากให้ใช้ วันที่ค้นก็ได้หรือกรอกเลขที่เอกสารก็ได้แบบนี้อะครับ ผมลองใช้
(SOHD.DocuDate BETWEEN '$date1' AND '$date2') OR (DocuNo LIKE '%$txtKeyword%') ข้อมูลมาหมดเลยครับ ผมพลาดตรงไหนรึป่าวครับ
$stmt = $conn->prepare("SELECT TOP 500 * FROM SOHD LEFT JOIN EMCust ON EMCust.CustID=SOHD.CustID WHERE SOHD.EmpID='$empid' AND SOHD.DocuStatus = 'N' AND (SOHD.DocuDate BETWEEN '$date1' AND '$date2' OR SOHD.DocuNo LIKE '%$txtKeyword%') ORDER BY DocuDate DESC");
$con1 = "SOHD.DocuDate BETWEEN '$date1' AND '$date2' "
. ($txtKeyword>''? " OR SOHD.DocuNo LIKE '%$txtKeyword%'" : '');
$sql = <<<sql
SELECT TOP 500 * FROM SOHD
LEFT JOIN EMCust ON EMCust.CustID=SOHD.CustID
WHERE SOHD.EmpID='{$empid}'
AND SOHD.DocuStatus = 'N'
AND ({$con1})
ORDER BY DocuDate DESC
sql;
$stmt = $conn->prepare($sql);
$con1 = "SOHD.DocuDate BETWEEN :d1 AND :d2 " . ($txtKeyword>''? " OR SOHD.DocuNo LIKE :lk1 " : '');
$sql = <<<sql
SELECT TOP 500 * FROM SOHD
LEFT JOIN EMCust ON EMCust.CustID=SOHD.CustID
WHERE SOHD.EmpID=:id
AND SOHD.DocuStatus = 'N'
AND ({$con1})
ORDER BY DocuDate DESC
sql;
$stmt = $conn->prepare($sql);
$stmt->bindParam(':id', $empid);
$stmt->bindParam(':d1', $date1);
$stmt->bindParam(':d2', $date2);
if( $txtKeyword>''){
$stmt->bindParam(':lk1', $txtKeyword);
}
$stmt->execute();