List default value
6 posts by 2 authors in: Forums > CMS Builder
Last Post: May 14, 2019 (RSS)
By Jesus - April 8, 2019
Hello,
I'm working on a directory project. 1st I'm creating a Category editor.
I'm creating a CatRoot field (list a field) where I need to have a default value (0|Root) for every record.
I'm also using here a list options as for subcategories I'll need to select the main category for each record. So my list options are like in the attached file.
Basically I just want to have a default value for each record (0|Root) (Number zero (as the value) and Root (as the label)).
Thanks!
By gregThomas - April 12, 2019
Hey Jesus,
So it looks like you're trying to insert a custom first row into your results with a value of 0 and label of root. You can do this by converting the field use custom MySQL, then adding a first custom row. I found a Stackover flow post that show's how to do that here:
So you'll need to change the CatRoot field List option from 'Get options from database (advanced)' to 'Get options from MySQL query (advanced)'. Then add the following custom MySQL command:
SELECT '0' as num, 'Root' as title
UNION ALL
SELECT `num`, `categoria`
FROM `<?php echo $TABLE_PREFIX ?>categorias`
This is just example code, so you might need to make a few changes to get it working with your setup.
Cheers,
Greg
PHP Programmer - interactivetools.com
By Jesus - May 12, 2019
Thank you Greg this worked :)
Now, how can I save the record for this field (as I'm thinking to relate this record for my Sites section like this:
0|Root
1|Arte y Cultura
2|Arte y cultura/Nuevo León
3|Arte y cultura/Nuevo León/Centros Culturales
4|Arte y cultura/Nuevo León/Galerias de arte
5|Ciencia y tecnologia
6|Ciencia y tecnologia/Ciencias de la Tierra y del Espacio
7|Ciencia y tecnologia/Ciencias de la Tierra y del Espacio/Astronomía
8|Deportes y entretenimiento
ETC
I'm thinking just one field (in place of two) as I'll use it later in my Sites section in order to build the permalink for detailed pages.
Thanks!
Jesus
By gregThomas - May 13, 2019
Hey Jesus,
So you want to display the breadcrumb (the parent records title field of each entry in the drop-down) as the records are from a category section?
Do you have a field that contains the value you want to display? For example, for the record Centros Culturales, do you have a field that contains Arte y cultura/Nuevo León/Centros Culturales?
PHP Programmer - interactivetools.com
By Jesus - May 13, 2019
No, but that's exactly what I'm trying to do.
Right now my category table looks like this:
- Title (Category name)
- Subcategory of (select list)
- Description
- permalink
Then in my Listing table I currently have:
- Title
- Category (list of categories from my category table)
- URL
- Description
- permalink
I want to display one page per each category with all the Sites (listings)
Example:
http://mysites.com/category/subcategory1/subcategory2/
That will display all listing from subcategory2
So... I'm trying to understand how can I accomplish this.
At this point I might need to add/include new fields on any table I'm just trying to make it work or to adjust the logic of all this in order to make it work
Thank you for your help!
Jesus
By gregThomas - May 14, 2019
Hey Jesus,
Thanks for the extra details. You'll need to update the category dropdown in the listings table so that it shows the permalink as the label. Then you can use the getRecords function to pull all of the relevant listings on the category detail page on the front end of the site.
Cheers,
Greg
PHP Programmer - interactivetools.com