php - Datetime range using between for switch case data search

I've been trying to make this query condition work. I'm making a Datatable search using PHP.
The agent, ID, and number could be search properly but when the datetime range is involved, the datetime is not working.
Please help. Thank you.
Here is the code:
$name = "";
$id = "";
$phone = "";
$queryCondition = "";
if(!empty($_POST["search"])) {
foreach($_POST["search"] as $k=>$v){
if(!empty($v)) {
$queryCases = array("datetime","name","id","phone");
if(in_array($k,$queryCases)) {
if(!empty($queryCondition)) {
$queryCondition .= " AND ";
} else {
$queryCondition .= " WHERE ";
}
}
switch($k) {
case "datetime":
$date_from=$_POST[date_from];
$date_to=$_POST[date_to];
$queryCondition .= "datetime BETWEEN '" . $date_from . "' AND '" . $date_to . "' ";
break;
case "agent":
$name = $v;
$queryCondition .= "name LIKE '" . $v . "%'";
break;
case "id":
$id_yoda = $v;
$queryCondition .= "id LIKE '" . $v . "%'";
break;
case "phone":
$po_phone = $v;
$queryCondition .= "phone LIKE '" . $v . "%'";
break;
}
}
}
}
$orderby = "ORDER BY id desc";
$sql = "SELECT * FROM datatable" . $queryCondition;
$result = mysqli_query($conn,$sql);
?>```
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: sqlstate[23000]: integrity constraint violation: 1452 cannot add or update a child row: a foreign key constraint fails
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.