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!

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

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?

Greg Thomas







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

Greg Thomas







PHP Programmer - interactivetools.com