Sending multiple values via ajax.data() to $editor->where() end looping through where()
Sending multiple values via ajax.data() to $editor->where() end looping through where()
I want send multiple values via ajax.data() // by e.g. selecting multiple input values // to $editor->where() and then loop through the where condition. How can this be done?
table = $('#my-table').DataTable( {
dom: "Blfrtip",
ajax: {
url: "/data.php",
type: "POST",
data: function (d) {
d.select = $('.select-status').val();
}
},
serverSide: true,
processing: true,
...
});
in data.php
->where( function ( $q ) {
$q->where( 'country', 'DE' );
$q->or_where( function ( $r ) {
$r->where( 'country', 'US' );
$r->or_where( function ( $s ) {
$s->where( 'country', 'GB' );
});
});
})
The above where() filters 'DE', 'US' and 'GB' from the database and renders it.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Anybody an idea?
To check I understand correctly, the
.select-status
is aselect
withmultiple
set? If so, it will submit an array, so you would just loop over that array:Allan
Thanks Allan. The suggested loop is returning all the values though.
Yes, the .select-status is a multiple select set:
... and after the .DataTable() instance I .ajax.reload() the table:
A alert test:
... shows that the data is thrown back as:
US,GB,DK,SE,NO,DE,LU
... if I select the values
Are you able to give me a link to the page please? I'm not sure what you mean by returning all of the values I'm afraid. Do you mean that the WHERE condition is not being applied? Is the loop executing?
Allan
Hi Allan. Now it's working ... almost :-) An underline '_' was missing in the example above. Now the loop is working if it's the only condition:
Many thanks for that. Yet, if I use further conditions (which work if I use them without the loop above) like ...
the loop still works, but then the other conditions won't work (they do filter, but only some very limited filtering is done). Is it possible to use the loop and all the other conditions together?
Good to hear you are getting closer. The issue now is likely the grouping - you need to group the
OR
conditions together. For that you can use thewhere_group
method.for example.
Allan
Brilliant! It's working like a charm, thanks a lot!