Creating an advanced list based on the table in another field

5 posts by 2 authors in: Forums > CMS Builder
Last Post: September 1, 2020   (RSS)

By garyhoffmann - August 28, 2020

I sincerely apologize if this has been asked/answered already...

I have two fields - the first field I would like to pick a table to use, the second field would be an entry in that table.

For the first table, I have the following list code in my field definition:

SELECT REPLACE(TABLE_NAME, '<?php echo $TABLE_PREFIX;?>', '') FROM information_schema.`TABLES` where TABLE_SCHEMA = '<?php echo $GLOBALS['SETTINGS']['mysql']['database'];?>' AND TABLE_NAME like '<?php echo $TABLE_PREFIX;?>_%' ORDER BY TABLE_NAME

For my second field, I would like to show the title field from table and capture the "num" field.  For example, I have the following so far:

SELECT num, title
FROM `<?php echo $TABLE_PREFIX ?>tableName`

What I'm not sure how to do is to replace the value "tableName" with the value of the previous field.  Ultimately, I want this to be:

SELECT num, title FROM <table selected in the previous field>

Is that possible?

Thank you in advance.

Gary.

By garyhoffmann - August 28, 2020

Nevermind - I found the ESCAPED_FILTER_VALUE and it works great!

So, now my query is:

SELECT num, title
FROM `<?php echo $TABLE_PREFIX ?><?php echo $ESCAPED_FILTER_VALUE ?>_images`

I'm selecting the "Gallery" in one field and then selecting the num/title for an entry in the same named section + _images.  For example, if the gallery is slideshow_gallery, the images are slideshow_gallery_images.

Gary.

By garyhoffmann - August 28, 2020

I spoke too soon - this is a problem when there is no value in the $ESCAPED_FILTER_VALUE field.

So, I guess I not only need to create a list based on this value, but also need to know if the field has a value.

Gary.

By garyhoffmann - September 1, 2020 - edited: September 1, 2020

That's awesome and does work.  Thank you!  I was not aware that basically you could put any PHP you wanted in that area.  That makes life a lot easier.