Only show results based on values
Only show results based on values
bwdgrp
Posts: 2Questions: 1Answers: 0
This is quite a simple question but struggling to find the answer.
We have connected a datatable to a MySQL database and it is showing 2 values
- job_id
- job_customer_id
Currently it's showing all results from the table 'jobs' but we want to use a PHP variable for the job_customer_id so only these jobs are visible to that specific customer.
We assume a filter rule on the data ?
$('#jobs').DataTable({
processing: true,
serverSide: true,
ajax: 'demo.php',
columns: [
{ data: 'job_id' },
{ data: 'job_customer_id' },
],
});
});
Answers
Are you wanting to send the
job_customer_id
from the client to the server in the ajax request? If so see this example for sending parameters to the server usingajax.data
as a function. Then the server script can use the parameter to filter the results sent to the client.Kevin
Hello Kevin.
We only want to show the logged in customers their own jobs, so usually in a SQL it would look like this.
SELECT * FROM jobs WHERE job_customer_id = '66'
The ajax.data option looks like it is what we need, if you have a sample code to demonstrate this using this field that would be useful.
Thanks
The only example I know of is the one I linked to. From the client you will need a way to get the
job_customer_id
to send to the server. How is dependent on your solution. Usingajax.data
the parameter will be sent along with the server side processing parameters.I don't use PHP but you will need to use standard PHP techniques to get the GET or POST data sent to the server. Are you using a Datatables provided server side processing script? Depending on the server script being used will determine how to build the where clause.
Kevin