Tengo un fetch para mostrar datos a una Datatable y quiero que me traiga información desde MySQL filtrado por un id- El problema está en que me sigue mostrando toda la información. La consulta la armo con: 'SELECT * FROM user WHERE id = 10' y concateno esto por cada valor que tengo: 'AND first_name LIKE "%' . $_POST["search"]["value"] . '%" OR last_name LIKE "%' . $_POST["search"]["value"] . '%"' --- Lo que finalmente intento es que llegue una variable POST (pero para hacer pruebas estoy poniendo un numero con un id). El código del fetch: <?php $connect = mysqli_connect("localhost", "root", "root", "testing"); $columns = array( 'first_name', 'last_name' ); $query = "SELECT * FROM user WHERE id = 10"; if (isset($_POST["search"]["value"])) { $query .= ' AND first_name LIKE "%' . $_POST["search"]["value"] . '%" OR last_name LIKE "%' . $_POST["search"]["value"] . '%" '; } if (isset($_POST["order"])) { $query .= 'ORDER BY ' . $columns[$_POST['order']['0']['column']] . ' ' . $_POST['order']['0']['dir'] . ' '; } else { $query .= 'ORDER BY id DESC '; } $query1 = ''; if ($_POST["length"] != -1) { $query1 = 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length']; } $number_filter_row = mysqli_num_rows(mysqli_query($connect, $query)); $result = mysqli_query($connect, $query . $query1); $data = array(); while ($row = mysqli_fetch_array($result)) { $sub_array = array(); $sub_array[] = '<div contenteditable class="update" data- id="' . $row["id"] . '" data-column="first_name">' . $row["first_name"] . '</div>'; $sub_array[] = '<div contenteditable class="update" data- id="' . $row["id"] . '" data-column="last_name">' . $row["last_name"] . '</div>'; $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($connect) { $query = "SELECT * FROM user"; $result = mysqli_query($connect, $query); return mysqli_num_rows($result); } $output = array( "draw" => intval($_POST["draw"]), "recordsTotal" => get_all_data($connect), "recordsFiltered" => $number_filter_row, "data" => $data ); echo json_encode($output); ?>