Hello everyone,
I want to change a query when the logging user id gets change.
Assume if user 1 logged to the system he can view all the fields of table.
if user 2 logged to the system he can view 2 or 3 or may be 5 fields of the table.but user 2 cannot view all the fields.
I think it gonna be changed at where clause of the query.
There should be one select query.query will be change dynamically when logging user id changes.
I hope all understood my problem.
Please be kind enough to share the knowledge.
Thank you...
how to change a sql querydynamicaly where user id get change
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: how to change a sql querydynamicaly where user id get ch
How many types of users are there? If you only have 2 types it would be easy to create two seperate queries, each already containing fields that can only be viewed by each type of user.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: how to change a sql querydynamicaly where user id get ch
Thank you for reply,but i need to maintain only one select query.
select query can be different when the different users are logged in to the system.
But i think it is difficult to that.But my boss want it to happen.
I got your idea to make different access levels but i'm keep trying to fulfill my bosses idea.
So if u can give me a support.
thanks again for your help...
Code: Select all
SELECT (fields name) where userid='***'But i think it is difficult to that.But my boss want it to happen.
I got your idea to make different access levels but i'm keep trying to fulfill my bosses idea.
So if u can give me a support.
thanks again for your help...
-
kalpesh.mahida
- Forum Commoner
- Posts: 36
- Joined: Wed Oct 06, 2010 7:09 am
Re: how to change a sql querydynamicaly where user id get ch
Do one thing prepare two array one for holding fields which user with id 1 can have access and second for user with id 2 can access
Like
now you have user id of logged in user, right? you just have to put condition to prepare fields part of your query based on logged in user.
Hope this will help you.
Kalpesh Mahida
Like
Code: Select all
$arr1 = array('fld1','fld2','fld3','fld4','fld5','fld6');
$arr2 = array('fld1','fld3','fld5',fld6');
Code: Select all
$fieldStr = '';
if($loggedInUid == 1) {
// prepare $fieldStr here using $arr1
} else if ($loggedInUid == 2) {
// prepare $fieldStr here using $arr2
}
Kalpesh Mahida
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: how to change a sql querydynamicaly where user id get ch
kalpesh.mahida has a similar idea to what i had in mind, using arrays. Once you have the array you can implode the values into a string and insert it into your query.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering