Query in editor
Query in editor
antoniocib
Posts: 277Questions: 62Answers: 1
Good morning,
I have a problem with these two Where in practice I set the two dates to view the data that must be mandatory and I would like to put the driver's entry as optional.
I just don't understand how to set up the query can you help me?
->where( function ($q) {
if (isset($_POST['startDate'] )) {
$q->where('data_bxd', $_POST['startDate'], '>=');
$q->where('data_bxd', $_POST['endDate'], '<=');
// $q->where('nome_aut', $_POST['autista'],'=');
}
else{
$q->where('','0000-00-00');
}
}
)
->where( function ($q) {
if (isset($_POST['autista'])) {
$q->where('nome_aut', $_POST['autista'],'=');
}
else if(is_null($_POST)){
}
}
)
This question has an accepted answers - jump to answer
Answers
Reformatted:
That looks perfectly reasonable to me. Are you getting an error or something else? I'm not clear on what the issue is.
Allan
@allan
It is not that I get some error it does not generate any json and as if the query did not work.
the operation I want to have is:
Mandatory date
"Autista" if the select has value, search for "autista" + date, instead if "autista" has not been validated, search only for date.
Add
->debug(true)
just before the->process()
call - that will result in the SQL being executed being returned to the client-side. What is the JSON returned please?Allan
@allan this is:
Many thanks - so that is showing:
And
where_2
is being bound as an empty string. So I'd say:is the condition you want (i.e.
autista
is set, but is an empty string at the moment - you need to take that into account).Allan
@allan works in this way thanks man!