Get record from Title name

9 posts by 3 authors in: Forums > CMS Builder
Last Post: June 16, 2013   (RSS)

By dccreatives - May 20, 2013 - edited: May 20, 2013

I have some code which I switched around. 

Currently, my page returns results with this: 


<?php echo $record['mounting'] ?>

I want it to return the title for each mounting record, not the name. How do I do this.

See it live here: http://www.axislighting.com/CMS_french/search_products.php

This page returns the results on the right. The pendant, wall is english and i added french to the title for the french pages.

Thank You.

By gregThomas - May 20, 2013

Hi,

Is the name of your title field title in the CMS? If so you should just need to change the field to this:

<?php echo $record['title'] ?>

If you're unsure of the name of the field, you can log into your CMS Builder admin area, then go to the Section Editor area, click the modify link on the items section, and on the section editors page look for the fields name in the field name column.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By dccreatives - May 20, 2013

The search results page reads from other pages.

Did you see the attached file?

Mounting is a section. Within mounting there is name and title.

Right now this code is giving me  <?php echo $record['mounting'] ?>

The mounting name automatically without the title.

I made the title french and I want it to show the french on this page without redoing the whole section and applying it...

Thanks.

By gregThomas - May 20, 2013

Hi,

I can't see anywhere the attached file references a mounting section. How is the mounting section linked to the items section? Is via this method:

http://www.interactivetools.com/kb/article.php?Populate-a-list-field-from-another-section-15

With the mounting field linking to the mounting section? 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By dccreatives - May 20, 2013

yes. 

Here is the search results page

Attachments:

search_products_001.php 7K

By gregThomas - May 20, 2013

Hi,

Assuming the value for your members field in the items section is the num field the following code should work:

  list($itemsRecords, $itemsMetaData) = getRecords(array(
      'tableName'   => 'items',
      'debugSql'    => false,
      'where'       => $where,
      'allowSearch' => false,
      'leftJoin'    => array(        // Note: leftJoins require you to use fully qualified fieldnames in WHERE and ORDER BY, such as tablename.fieldname
        'mounting'  => 'mounting', // foreign table => local field (that matches num in foreign table)
      ),
  ));

Then you need to modify the way the title is shown to this:

<?php echo $record['mounting.title'] ?>

This is just example code, so you might have to make a few changes to get it working.

So I've added a leftJoin statement to the getRecords function. This will take the value from the mounting list field in items section, and retrieve a record with the same num value in the mounting section. All of the fields from the mounting section will be returned in the array with mounting. proceeding them, for example mounting.title, mounting.name.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By dccreatives - May 21, 2013

I added the script that you gave me.

You can see the error here.

http://www.axislighting.com/CMS_french/search_products-f.php

It was pulling the mounting type from the items from the mounting fields and it took the name. Now I want it to take the title and it is getting complicated...

By Deborah - June 16, 2013

Greg,

I just had to reply to say this code worked PERFECTLY for me and was just what I needed today for a project on deadline.

Always happy the forum is here for us all to learn from. Thanks so much for this post!

~ Deborah