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 zaba - May 1, 2014
Hi I want to populate a related record block but only show certain fields in the related table.
how would I do this? or can I do it?
so the relation ship in the MYSQL where clause is
book_ref='<?php echo mysql_escape(@$RECORD['book_ref']) ?>'
This brings in the all the fields (as columns) in the other table, whereas I only need to show half of them (but all the rows in the relationship).
Is there a way to do a full MySQL SELECT field1, field2, field3, field4 FROM table_name WHERE book_ref='<?php echo mysql_escape(@$RECORD['book_ref']) ?>'
help :-)
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
PHP Programmer - interactivetools.com