filter list to show only current users options
2 posts by 2 authors in: Forums > CMS Builder
Last Post: February 28, 2013 (RSS)
By 4cdg - February 28, 2013
I have 2 multi-tables one called Listings and one called Agents.
I also have around 30 users who are authors for these 2 tables
I would like to call all the agents into a dropdown list in the listings table (which i know how to do), but i only want the agents created by the current user to display in the dropdown when they are creating or modifying their listings records
When i set it up all agents are availble to all users.
Hi,
To do this first you need to change the list fields 'list option' to 'Get options from MySQL query (advanced)'. This will allow you to add a custom MySQL statement to filter out only the agents you need. I think your code will need to look something like this:
SELECT num, name
FROM `<?php echo $TABLE_PREFIX ?>agents`
WHERE createdByUserNum = '<?php echo $CURRENT_USER['num']; ?>'
This is just example code, so you will need to change some of the variable names to get it to work with your sections.
The select line should contain the two fields you want to be used for the value and label of the field.
The from line should have the table you want to get your results from.
The where statement is checking the CMS Builder field createdByUserNum is equal to the current users num value, so it should only return results created by the current user.
Let me know if you have any questions.
Thanks!
Greg
PHP Programmer - interactivetools.com