Best way to use link field option

18 posts by 6 authors in: Forums > CMS Builder
Last Post: March 29, 2010   (RSS)

By _kate_ - March 24, 2009

Hi,
I am working on a real estate website. I have made up a section called "rentals" which contain standard type of fields, including one called "Agent" where they will be able to enter the agent for that property.

Since they have so many properties I figured it would be easier to make a separate multi record section called "Agents" with the fields name, email, phone where each agents details would be entered once.

I went back to Rentals and edited the agents field and made it a list, with the data coming from the database, agents.

Problem is it only displays one field e.g. name and not all the fields for an agent as you are able to only specify one field in the options.

What can I do to make this work, or alternatively what would be the best to way to go about doing what I am trying to achieve? I am hoping that for each new property, the client can select the agent from a drop down list of existing agents and on the site it will display the agent name, email and phone number. Would also be good if they could add/edit agents.

Hope that makes sense :) Thanks!!

Re: [_kate_] Best way to use link field option

By ross - March 24, 2009

Hi Kate

Thanks for posting!

With a bit of custom MySQL there should be a few different options for you here. I just want to make sure I am on the right track here first :).

You want to have your listing pages display details about the agent that created them. The agent details are stored in a different table though.

When you create a new listing, you just select the agent name from a drop down list.

Let me know if this sounds like what you need and I'll go over the code with you :).

Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] Best way to use link field option

By _kate_ - March 24, 2009 - edited: March 24, 2009

Hi Ross,
Thanks for your reply.

It doesn't have to be the person that created the listing - the secretary will probably do all of these. I just thought it could save some if they didn't have to enter the agents details for every listing.

I am making a real estate page with a listing layout like the page below >
http://www.colliersresidential.com/listings.cgi?listing=4893&perpage=20&rm=viewListing&s=r

See the bit down the side with the agent details? I made an agent field for these details with a WYSIWYG field. Then it occured to me with hundreds of listings, they would have to keep typing the same info so I tried to make a list field which they could choose the agent name from and linked it to a new section called "Agents". It works fine in the CMS, but on the site it only displays the one field - agent name as in the CMS it will only let me select one field for the content...

Sorry I am trying to explain it as clearly as possible... it doesn't have to work exactly how I mentioned, jhust need the best solution for the above problem :)

Re: [ross] Best way to use link field option

By _kate_ - April 2, 2009

Does anyone have an answer to this problem?

As expected the client has seen the site and requested that she can pick the agents from a list instead of having to type it in for every listing.

Does anyone know how I could get this working?

Thanks!

Re: [_kate_] Best way to use link field option

By ross - April 2, 2009

Hi Kate.

What you are going to need here is a new section called Agents. Set it up with all the fields you want and then let me know. You'll basically be filling out one page for each Agent and then just selecting their name from a drop down when you create a new listing.

Then with some PHP on your listing page, we can pull in the proper agent details without you having to enter them every time.

Let me know once you have that section setup and we'll go from there. Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] Best way to use link field option

By _kate_ - April 2, 2009

Hi Ross,
I had already set up the agents section with the required fields. The problem came when I tried to connect it to the listings section. Not sure I did it right as the data wouldn't all display. Added a list field and told it to pull data from agents field so you could pick the agent from a drop down - seemed I could only pick one data field to display on setup instead of showing them all. So is that the correct way to do it and then use a code that lets u display all the data? Or do I need to do something else?

Thanks!

Re: [_kate_] Best way to use link field option

By ross - April 3, 2009

Hi Kate.

It sounds like you are on the right track. I am actually thinking we could try this a slightly different way though :).

In your viewer code on your listing page, you probably have something like this:

list($listingRecords, $listingDetails) = getRecords(array(
'tableName' => 'listings',
'perPage' => '10',

));


could you try adding in -- 'joinTable' => 'homepages', -- so you get

list($listingRecords, $listingDetails) = getRecords(array(
'tableName' => 'listings',
'joinTable' => 'homepages',
'perPage' => '10',

));


You need to make sure 'homepages' is the name of your agents table.

Then, where you have all the details appear, you can call in the fields from your agent tables like this:

<?php echo $listing['homepages.fullname'] ?>

This will pull in the name of the agent that created the listing.

Give that shot and let me know how you make out :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] Best way to use link field option

By _kate_ - April 5, 2009 - edited: April 5, 2009

Hi Ross,
Did as instructed, yet not quite working yet. This is going on the detail page so maybe I need to adjust some code for that? Here's what I've got so far >

<?php
require_once "/mysite/viewer_functions.php";

list($salesRecords, $salesMetaData) = getRecords(array(
'tableName' => 'sales',
'joinTable' => 'agents',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$salesRecord = @$salesRecords[0]; // get first record

// show error message if no matching record is found
if (!$salesRecord) {
print "Record not found!";
exit;
}

?>


And to display the agent details >

<?php echo $salesRecord['agents.title'] ?>
<?php echo $salesRecord['agents.content'] ?>


There is no error message showing where the agents detail should appear - instead it just remains blank...

Re: [ross] Best way to use link field option

By _kate_ - April 10, 2009 - edited: April 10, 2009

Hi Ross,
I *think* we are getting there :P

Ok so after the client edited a couple of the agent records, data is now showing on the site as it should - only problem is for some reason it doesn't show the agent you selected, it is instead just showing ONE of the records for every single listing.

I thought maybe it was showing the first agent listed in the CMS and experimented moving them around with the drag/drop, but it still shows the same agent regardless. Strangely the same thing happens in the rentals section, instead it is displaying a different agent and doing it for every single one as well regardless of whats selected.

Any ideas what is going on here? When linking the sections, in the Field Options I chose
Section Tablename - agents
Use this field for option values - title
Use this field for option labels - title

The agents section has 2 fields - title and content.