Add condition where to filter data display from mysql
Add condition where to filter data display from mysql
Hello everyone , i want to add a where condition to filter the data to display . I tried adding this to my query: WHERE mony = '1-2023' , but nothing happens. I searched and found the following instructions: $editor->where( 'mony', 1-2023); .But it has no further instructions anywhere. I really hope everyone helps.
Here is my fetch.php file:
`<?php
//fetch.php
include ("../includes/dbconnect.php");
$columns = array('nost', 'manv', 'ten','shift', 'phone','namechina','mony','st1','st2','st3','st4',
'st5','st6','st7','st8','st9','st10','st11','st12','st13','st14','st15','st16','st17','st18','st19','st20','st21','st22','st23',
'st24','st25','st26','st27','st28','st29','st30','st31');
$query = "SELECT * FROM alternate";
if(isset($_POST["search"]["value"]))
{
$query .= '
WHERE manv LIKE "%'.$_POST["search"]["value"].'%"
OR ten LIKE "%'.$_POST["search"]["value"].'%" OR shift LIKE "%'.$_POST["search"]["value"].'%" OR mony LIKE "%'.$_POST["search"]["value"].'%"
';
}
if(isset($_POST["order"]))
{
$query .= 'ORDER BY '.$columns[$_POST['order']['0']['column']].' '.$_POST['order']['0']['dir'].'
';
}
else
{
$query .= 'ORDER BY mony ASC ';
}
$query1 = '';
if($_POST["length"] != -1)
{
$query1 = 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
}
$number_filter_row = mysqli_num_rows(mysqli_query($connection, $query));
$result = mysqli_query($connection, $query . $query1);
$data = array();
while($row = mysqli_fetch_array($result))
{
$sub_array = array();
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '
';
$sub_array[] = '<button type="button" name="delete" class="btn btn-danger btn-xs delete" id="'.$row["id"].'">Delete</button>';
$data[] = $sub_array;
}
function get_all_data($connection)
{
$query = "SELECT * FROM alternate WHERE mony ='1-2023'";
$result = mysqli_query($connection, $query);
return mysqli_num_rows($result);
}
$output = array(
"draw" => intval($_POST["draw"]),
"recordsTotal" => get_all_data($connection),
"recordsFiltered" => $number_filter_row,
"data" => $data
);
echo json_encode($output);
<?php > ` ?>
Answers
Probably because no column matches. What is the field definition of "mony"?
Are you using Editor at all? Your code doesn't look like it.
Please note: This forum won't give you advice on general SQL questions. For that please refer to Stack Overflow etc. If you have questions regarding Editor or the SSP class we can help you here.
I don't use editor , that's what I see when I google it
Ok, then I would refer to Stack Overflow to find out what is wrong with your proprietary SQL.
@rf1234 'mony' is a column in the datatable where I note the month of May
"1-2023" doesn't look like the month of May ... But anyway I would post this on SO.
@rf1234 thank you