Add condition where to filter data display from mysql

Add condition where to filter data display from mysql

thang98thang98 Posts: 4Questions: 1Answers: 0

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[] = '

' . $row["nost"] . '

';
$sub_array[] = '

' . $row["manv"] . '

';
$sub_array[] = '

' . $row["ten"] . '

';
$sub_array[] = '

' . $row["shift"] . '

';
$sub_array[] = '

' . $row["phone"] . '

';
$sub_array[] = '

' . $row["namechina"] . '

';
$sub_array[] = '

' . $row["mony"] . '

';
$sub_array[] = '

' . $row["st1"] . '

';
$sub_array[] = '

' . $row["st2"] . '

';
$sub_array[] = '

' . $row["st3"] . '

';
$sub_array[] = '

' . $row["st4"] . '

';
$sub_array[] = '

' . $row["st5"] . '

';
$sub_array[] = '

' . $row["st6"] . '

';
$sub_array[] = '

' . $row["st7"] . '

';
$sub_array[] = '

' . $row["st8"] . '

';
$sub_array[] = '

' . $row["st9"] . '

';
$sub_array[] = '

' . $row["st10"] . '

';
$sub_array[] = '

' . $row["st11"] . '

';
$sub_array[] = '

' . $row["st12"] . '

';
$sub_array[] = '

' . $row["st13"] . '

';
$sub_array[] = '

' . $row["st14"] . '

';
$sub_array[] = '

' . $row["st15"] . '

';
$sub_array[] = '

' . $row["st16"] . '

';
$sub_array[] = '

' . $row["st17"] . '

';
$sub_array[] = '

' . $row["st18"] . '

';
$sub_array[] = '

' . $row["st19"] . '

';
$sub_array[] = '

' . $row["st20"] . '

';
$sub_array[] = '

' . $row["st21"] . '

';
$sub_array[] = '

' . $row["st22"] . '

';
$sub_array[] = '

' . $row["st23"] . '

';
$sub_array[] = '

' . $row["st24"] . '

';
$sub_array[] = '

' . $row["st25"] . '

';
$sub_array[] = '

' . $row["st26"] . '

';
$sub_array[] = '

' . $row["st27"] . '

';
$sub_array[] = '

' . $row["st28"] . '

';
$sub_array[] = '

' . $row["st29"] . '

';
$sub_array[] = '

' . $row["st30"] . '

';
$sub_array[] = '

' . $row["st31"] . '

';
$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

  • rf1234rf1234 Posts: 2,922Questions: 87Answers: 414
    edited February 2023

    I tried adding this to my query: WHERE mony = '1-2023' , but nothing happens.

    Probably because no column matches. What is the field definition of "mony"?

    I searched and found the following instructions: $editor->where( 'mony', 1-2023); .But it has no further instructions anywhere.

    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.

  • thang98thang98 Posts: 4Questions: 1Answers: 0

    I don't use editor , that's what I see when I google it

  • rf1234rf1234 Posts: 2,922Questions: 87Answers: 414

    Ok, then I would refer to Stack Overflow to find out what is wrong with your proprietary SQL.

  • thang98thang98 Posts: 4Questions: 1Answers: 0
    edited February 2023

    @rf1234 'mony' is a column in the datatable where I note the month of May

  • rf1234rf1234 Posts: 2,922Questions: 87Answers: 414

    '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.

  • thang98thang98 Posts: 4Questions: 1Answers: 0

    @rf1234 thank you

Sign In or Register to comment.