我遇到这种情况:
我通过表单进行的所有搜索工作都很完美,但是当我设置日期时它什么也没有返回...如果查询有效,那还有什么想法?
JS PAGE
$( '#frm_ricerca' )
.submit( function( e ) {
console.log('fired');
$("#ricerca_btn").html('Caricamento in corso...');
table.clear().draw();
ZEUS.Notification('bottom', 'center', 'Ricerca Avviata', 1);
e.preventDefault();
$.ajax( {
url: 'index.php?dispatch&token=XXXX&method=search_by',
type: 'POST',
data: new FormData( this ),
processData: false,
contentType: false,
success : function(datas){
$.each (datas, function(i, v){
table.row.add([v.fieldA, v.fieldB...]);
});
$("#count_research").text(datas.length + ' Elementi trovati');
$("#search_result").show();
table.draw();
$("#ricerca_btn").html('Ricerca');
},
error : function(e){
console.log("---- errore ----" );
console.log(e);
console.log("--- FINE ERRORE ---");
$("#ricerca_btn").html('Ricerca');
}
} );
} );
PHP PAGE
$searchKeys = array(
'id_operazione' => filter_input(INPUT_POST, 'reg_id', FILTER_SANITIZE_STRING),
'rapporto_numero' => filter_input(INPUT_POST, 'rapporto_numero', FILTER_SANITIZE_STRING),
'CONCAT(Cognome, \' \', Nome) ' => filter_input(INPUT_POST, 'nominativo', FILTER_SANITIZE_STRING),
'CodiceFiscale' => filter_input(INPUT_POST, 'cf', FILTER_SANITIZE_STRING),
'data_formazione >= ' => filter_input(INPUT_POST, 'data_dal', FILTER_SANITIZE_STRING),
'data_formazione <= ' => filter_input(INPUT_POST, 'data_al', FILTER_SANITIZE_STRING),
);
$mainQuery = 'SELECT id_operazione, Cognome, Nome, CodiceFiscale, data_formazione FROM database WHERE ';
foreach ($searchKeys as $field=>$value) {
if(!empty($value)){
if (strpos($field, 'Cognome') !== false) {
$mainQuery .= $field . " LIKE '%$value%' AND ";
} else if(strpos($field, 'data') !== false) {
$mainQuery .= $field . " '$value' AND ";
} else {
$mainQuery .= $field . " = '$value' AND ";
}
}
}
$mainQuery = substr($mainQuery, 0, -4);
$result = $mysqli->query($mainQuery);
$data = array();
if($result) {
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
if(empty($data)){
http_response_code(200);
echo json_encode(array("status"=>"succes", "message"=>"no data"));
} else {
http_response_code(200);
echo json_encode($data);
}
} else{
http_response_code(400);
echo json_encode(array("status"=>"error", "query"=>$mainQuery));
}
所以,基本上我的问题是,无论我使用哪种参数进行搜索都可以...
但如果我设置了1个或两个日期,则会给出200响应而没有数据......
任何想法?
- 更新 -
查询形成了使用日期
SELECT id_operazione, Cognome, Nome, CodiceFiscale, data_formazione FROM aui WHERE data_formazione >= '2017-01-01'
它返回我的状态200的错误....这更奇怪
答案 0 :(得分:1)