I need to send a parameter to server side processing by the selecting an option in list and the retrieve only the records that match the selection.
1) Javascript: What is the best way to send a parameter?
2) PHP: How can I get the value received and filter the array?
Html
<div class="form-group">
<label for="title">Pick Name:</label>
<select name="iname" class="form-control" onchange="showUser(this.value)" style="width:500px">
<option value="Fred">Fred</option>
<option value="Lucy">Lucy</option>
<option value="Amy">Amy</option>
<option value="Joe">Joe</option>
</select>
</div>
Javascript
function showUser(str){
$('#mytable').DataTable({
"bProcessing": true,
"sAjaxSource": "go1.php",
"aoColumns": [
{ mData: 'Name' },
{ mData: 'Start Date' },
{ mData: 'End Date' },
{ mData: 'Notes' }
]
});
};
PHP
$data = array(
array('Name'=>'Lucy', 'Start Date'=>'2017-11-01', 'End Date'=>'2017-11-01', 'Notes'=>'Notes02'),
array('Name'=>'Amy', 'Start Date'=>'2017-09-01', 'End Date'=>'2017-09-11', 'Notes'=>'Notes03'),
array('Name'=>'Fred', 'Start Date'=>'2017-02-03', 'End Date'=>'2017-02-04', 'Notes'=>'Notes04'),
array('Name'=>'Joe', 'Start Date'=>'2017-03-05', 'End Date'=>'2017-03-21', 'Notes'=>'Notes05')
);
$results = array(
'sEcho'=>'1',
'iTotalRecords'=>count($data),
'TotalDisplayRecords'=>count($data),
'aaData'=>$data
);
echo json_encode($results);
Regards, Elio Fernandes