Related Records (in admin) choose which fields to bring in

2 posts by 2 authors in: Forums > CMS Builder
Last Post: May 15, 2014   (RSS)

By gregThomas - May 15, 2014

Hi Zaba,

I think I understand what you're trying to achieve. So you have a related record list field like the one shown in the first attached screenshot. But you only want certain records to appear in the list field, depending on what is selected in another field?

This can be done using the Get option from MySQL query list type. The second screenshot I've attached shows you how to set up this list field type. Here is the MySQL code I used to set up the field:

SELECT num, CONCAT(`brand`, ' - ', country') 
  FROM `<?php echo $TABLE_PREFIX ?>brand`
  WHERE `country` = '<?php echo $TABLE_PREFIX ?>'

So in this example I have a cars section (F150, M3, Ka, 500, etc), and a list field in to select the cars brand from a brand section. I've also have a location field to the cars section, so you can select where the car is built. This is then used to filter the brand field so that it only displays brands from that location. For example, if I selected German as the location, only BMW, Volkswagen, Audi and Bugatti would  be shown in the brand field. 

The select needs to contain the two fields that you want to use as the value and the field description. I've used to MySQL concat function to combine two fields into one for the description. 

Finally the where statement is used to filter based on country, the $TABLE_PREFIX variable will contain the location the user selected. I ensured that the location will be in this variable by selecting the location field from the advanced filter list (This can be seen in the second screenshot).

Thanks!

Greg 

Greg Thomas







PHP Programmer - interactivetools.com
Attachments:

CMS Builder.png 55K

CMS Builder2.png 65K