Only show results based on values

Only show results based on values

bwdgrpbwdgrp 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

  • kthorngrenkthorngren Posts: 21,337Questions: 26Answers: 4,954

    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 using ajax.data as a function. Then the server script can use the parameter to filter the results sent to the client.

    Kevin

  • bwdgrpbwdgrp Posts: 2Questions: 1Answers: 0

    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

  • kthorngrenkthorngren Posts: 21,337Questions: 26Answers: 4,954

    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. Using ajax.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

Sign In or Register to comment.