whenever i use Where clasue in query, it is not working
i want to show some specific data by condition
i tried this below –
$query = “SELECT * FROM batch_details
where ins_name=’safi’ “;
but when i use where clause in query it doesn`t work
//fetch.php
include('database_connection.php');
$column = array("id", "batch_student_name","student_marks");
$query = "SELECT * FROM `batch_details` ";
if(isset($_POST["search"]["value"]))
{
$query .= '
WHERE batch_student_name LIKE "%'.$_POST["search"]["value"].'%" ';
}
if(isset($_POST["order"]))
{
$query .= 'ORDER BY '.$column[$_POST['order']['0']['column']].' '.$_POST['order']['0']['dir'].' ';
}
else
{
$query .= 'ORDER BY id ASC ';
}
$query1 = '';
if($_POST["length"] != -1)
{
$query1 = 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
}
$statement = $connect->prepare($query);
$statement->execute();
$number_filter_row = $statement->rowCount();
$result = $connect->query($query . $query1);
$data = array();
foreach($result as $row)
{
$sub_array = array();
$sub_array[] = $row['id'];
$sub_array[] = $row['batch_student_name'];
$sub_array[] = $row['student_marks'];
$data[] = $sub_array;
}
function count_all_data($connect)
{
$query = "SELECT * FROM `batch_details` ";
$statement = $connect->prepare($query);
$statement->execute();
return $statement->rowCount();
}
$output = array(
'draw' => intval($_POST['draw']),
'recordsTotal' => count_all_data($connect),
'recordsFiltered' => $number_filter_row,
'data' => $data
);
echo json_encode($output);