drop down list by MySQL Table , but only per user record

4 posts by 2 authors in: Forums > CMS Builder
Last Post: February 6, 2009   (RSS)

Hello

I was wondering if the following is possible:

I have 2 sections for useres with only "writer"-rights.

The first section is the section, where they can enter job-ads
The second section is an address section, where they can enter different adresses

Now, what I would like to do ist that, when they have entered adresses and a short-name for every adress, that they apear in the job-ad section, where they can choose from a drop down list, which is feeded by the adresses table with the short-name field. All works pretty fine except that the drop down list fills with short-names from adresses of other users as well.

In other words drop down lists that are feeded from a database table should alos have user-based restrictions, so that only the records from the logged-in user are displayed. This works fine for a whole section, but not if you use list fields that gather data from a database table, they should also be limited to the records of the actual logged-in user.

I hope I explained it well ;-)

Thanks for any advice, I guess this needs some modification in the admin section...

Kind Regards
Guido

Re: [guido_ch] drop down list by MySQL Table , but only per user record

By Dave - February 6, 2009

Hi Guido, welcome to the CMS Builder forum! :)

This isn't supported by the software but it is possible with some custom MySQL and PHP.

In the field editor you probably have your list field set to "Get options from database" followed by tableName, valueField, labelField (of course you'll have values selected for those).

What you want to do is change that to "Get options from MySQL query" and enter this:

SELECT valueField, labelField, FROM <?php echo $TABLE_PREFIX ?>tableName WHERE createdByUserNum = '<?php echo $GLOBALS['CURRENT_USER']['num'] ?>'

And replace the red fields with the actual names of your fields and table. What this does is load the same values but only return records that are created by the user who is currently logged in.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] drop down list by MySQL Table , but only per user record

Wow this was fast! Thank you very much!
Is there some documentation, where all these global-variables (like CURRENT_USER) are listed?

Cheers
Guido