Pre filter list using user id based attributes value

chofra02

Certified try and error specialist
Hi,

I have a table with weight_cat and age_cat as categories attribute. I would like to pre filter a list shown to the user to show only the entries of its own weight_cat and age_cat.
I save the user id as a database join in this table.

So I was thinking that it must be possible to build a pre filter like:

select * from table where weight_cat = user_id.weight_cat and age_cat = user_id.age_cat

what would be the expression to use in the filter in this case?

Thanks for your support.

Cheers
 
Something like this might work ...

First you would need to know what ag and weight categories the person viewing the table is in. You'd do that with a pre-filter query, something like this:

SELECT weight_cat, age_cat FROM yourtable WHERE user_id = {$my->id}

Replace the field and table names as appropriate. As the tooltip on the pre-filter query explains, that will execute this query prior to the main data query, and put the selected field results into an object called $q, which you can then use as placeholders in your prefilters. So in this case, {$q->age_cat} will be the age category we want.

So you can now add two pre-filters ...

Join: WHERE
Field: age_cat
Condition: EQUALS
Value: {$q->age_cat}
Type: text
Apply to: (whatever ACL is appropriate for your setup)
Grouped: No

Join: AND
Field: weight_cat
Condition: EQUALS
Value: {$q->weight_cat}
Type: text
Apply to: (whatever ACL is appropriate for your setup)
Grouped: Yes

If this doesn't work, load that page in fabrik debug mode, find the getData debug output (the main SELECT query for the list), and paste it here.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top