USING MYSQL QUERIES IN LIST FIELDS - Oct 30th, 2015


For this example, create a multi record section called "rules_list" with only one text field called "rules"

Then create another multi record section with one list field called "test" and choose "Get options from mySQL Query
(Advanced)" from the list options pull down.

You'll be presented with this generic query as an example.

SELECT field1, field2
FROM `<?php echo $TABLE_PREFIX ?>your_table`

field1 is the equivalent of the "Options Value"
field2 is the equivalent of the "Options Label" that will be displayed
your_table is the name of the section to pull these options from.

In this case, the section you'll get your options labels and options values from is the rules_list" table so enter
"rules_list" in place of your_table in the sample code
You'll be getting the Options Labels from the text field called "rules" so enter that as field2
Your options values will come from the "record number" so enter num as field1.

Your query should now look like this:

SELECT num, rule
FROM `<?php echo $TABLE_PREFIX ?>rules_list`


If you want to filter your list into groups you can add a new list field called "group" to the "rules_list" table, with
the sample values, Guidelines, Presentation Rules, and Required Entry Materials.

Then you can list only those records where the "group" field contains the text between the % signs below.

This example, we want to list all of the records that have Guidelines selected as the "group" value, so enter "guide"
between the % signs as below

SELECT num, rule
FROM `<?php echo $TABLE_PREFIX ?>rules_list`
WHERE `group` LIKE '%guide%'


To list only those records that are part of the "Required Entry Materials" group, change the characters between the %
signs to "reqi" or "mater"

Just make sure that the character string is unique to that group.

NOTE There are 2 sets of back ticks (under the tilde character "~") and one set of single quotes used in the code.



The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service