Change MySQL Query depending on the login

Change MySQL Query depending on the login

editortechappeditortechapp Posts: 2Questions: 1Answers: 0

Greetings,

First off Jquery Datatables is the greatest thing next to slice bread :smile

I have a login table that has username, account type etc and i want to only disable specific columns of another table depending on the user's account type. I searched the forums here and on stackoverflow but i cant find anything.

The only thing i can think of is building multiple tables and using javascript/jquery or php to hide/unhide the table depending on the login. I really dont want to do this.

So basically, if Account A log's in, I only want to show Columns 1234. If Account B log's in, i only want to show column 1 and 2.

Answers

  • allanallan Posts: 64,596Questions: 1Answers: 10,683 Site admin

    There are a few options for this. Showing and hiding columns is the least secure way to be honest, since if the user is technically savvy, they will be able to just unhide the hidden columns and view data they shouldn't be able to see!

    The method I normally take for this is to make an Ajax call to the server to get the DataTables configuration to be used - then initialise the DataTable with the object returned. That can optionally include the data to prevent the need for a second Ajax query to the server, but it should certainly include the column information. Then you just need to have a server-side script that will give that information, based on whatever access logic you need.

    Allan

  • editortechappeditortechapp Posts: 2Questions: 1Answers: 0

    i'm a junior developer, can you please give me an example?

  • allanallan Posts: 64,596Questions: 1Answers: 10,683 Site admin

    Certainly - I'd be happy to spend the time writing an example under the support options.

    Allan

This discussion has been closed.