Skip to main content
Topic: Filter data base on one of user data (Read 2687 times) previous topic - next topic

Filter data base on one of user data

hello Friends
I'm trying to Create View to filter records base on user department .
at sign in it require Department for the  user save in admin table  ,the when add  record in other table "archive" have field to add multiple value  which represent department that can see this file   , please note i'm normal user not professional and not well known of MySQL statement , i tried this code to filtrate it  ,
Code: [Select]
@DIVI="SELECT  a.Division FROM admin AS a WHERE  ( a.ID =USER_ID)",
SELECT
archive_app.ID,
archive_app.`Subject`,
archive_app.Reference_No,
archive_app.Details,
archive_app.Upload,
archive_app.Box_file_catg,
archive_app.Division,
archive_app.Uploader,
archive_app.Uploading_date,
archive_app.Statues,
archive_app.From__,
archive_app.Type__,
archive_app.Date,
archive_app.Source__
FROM
archive_app
WHERE
( @DIVI IN ( archive_app.Division ) )

please any one could  help me to do this ?.
thanx and sorry for my bad English lang.
Almosawi A.Mohammed

Re: Filter data base on one of user data

Reply #1
@mohif1995
Code: [Select]
SELECT aa.* FROM archive_app AS aa WHERE (SELECT ud.Division FROM admin AS ud WHERE ud.ID = ? ) IN (aa.Division)
and add USER_ID to the Edit Query Params area.

if it doesn't work then use the next query.
Code: [Select]
SELECT aa.* FROM archive_app AS aa WHERE (SELECT ud.Division FROM admin AS ud WHERE ud.ID =".USER_ID.") IN (aa.Division)

Re: Filter data base on one of user data

Reply #2
@mohif1995
Code: [Select]
SELECT aa.* FROM archive_app AS aa WHERE (SELECT ud.Division FROM admin AS ud WHERE ud.ID = ? ) IN (aa.Division)
and add USER_ID to the Edit Query Params area.

if it doesn't work then use the next query.
Code: [Select]
SELECT aa.* FROM archive_app AS aa WHERE (SELECT ud.Division FROM admin AS ud WHERE ud.ID =".USER_ID.") IN (aa.Division)


thanx @ willvin  For Your Quick response .
 I Tried Both code but not work for me, 
MD1 , Md12 images for  first code.
md2 ,md21 for second code.
mdadmin the Department value in admin table.
mdarchive the department value in archive table .

thanx again ,
sorry for my bad English .
Almosawi A.Mohammed


Re: Filter data base on one of user data

Reply #4
I sent Message to you , please check your inbox.
Almosawi A.Mohammed