6 posts by 2 authors in: Forums > CMS Builder
Last Post: May 14   (RSS)

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!

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:

https://stackoverflow.com/questions/24771349/how-can-i-add-a-custom-row-to-the-top-of-a-select-result-set

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

Greg Thomas
PHP Programmer - interactivetools.com

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

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?

Greg Thomas
PHP Programmer - interactivetools.com

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

Greg Thomas
PHP Programmer - interactivetools.com