Need help to search Inventory by Make/Model, but make/model in separate table

5 posts by 2 authors in: Forums > CMS Builder
Last Post: November 2, 2009   (RSS)

By Codee - October 29, 2009

We've set up our site to use the dynamic menus with heirarchy so we can do a lot of manufacturer/model and Equipment Type lists for vehicles. The challenge we're having is two-fold:

In CMSB Admin panel, under inventory section we are unable to search Inventory records by Manufacturer/Model or Equipment Type (because they are in separate sections from Inventory).

For the site visitors they are unable to search by Manufacturer/Model or Equipment type also. To solve that we bought and installed the Google search tool, but that did not perform as expected or refresh quickly enough so we replaced it with a search box that queries the CMSB database but it only queries the fields in the inventory section...so how can we make it query the inventory section, the make/model section, equipment type section and maybe the dealer info section?

We're in crunch on this now.

Re: [equinox69] Need help to search Inventory by Make/Model, but make/model in separate table

By Dave - October 29, 2009

Hi Terry,

If the tables are linked with a pulldown field you can add a new search field as we discussed in your other post and it should show a pulldown above the record list. So you could select a make or model from that.

I'm not sure exactly how your site is setup but I think that should work even if they are different sections.

As for searching multiple sections. Do you just want any records that match from any of those sections? Or inventory matches that can use keywords from other section records related to the inventory record?

The first step would be to create a mockup of the search form and results page you want to have.

But basically you can write some custom MySQL query code and pass that to the viewer functions to have them search joined tables or look for a keyword in multiple sections.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Need help to search Inventory by Make/Model, but make/model in separate table

By Codee - October 30, 2009

Dave,

If the tables are linked with a pulldown field you can add a new search field as we discussed in your other post and it should show a pulldown above the record list. So you could select a make or model from that.

Okay, I get that now...so to make this work for manufacturer I put the following into the "searching" portion of the section:
Manufacturer|manufacturer|match
and that works. But since model is a subcategory of manufacturer, if I just put Model|model|match then the field won't prepopulate.

Re: [equinox69] Need help to search Inventory by Make/Model, but make/model in separate table

By Dave - November 2, 2009

Hi Terry,

The problem with search every field is you'll start getting lots of irrelevant results when there are many records.
There's no simple and easy way to get search results from multiple related tables right now with CMS Builder.

There's is the following option, although it requires some more advanced PHP and MySQL skills:

'leftJoin' => array( // Note: leftJoins require you to use fully qualified fieldnames in WHERE and ORDER BY, such as tablename.fieldname
'foreignTable' => 'ON thisTable.foreignKey = foreignTable.num',
),

And that will make all the fields from the related table available for searching, but then you need to start using full tablename.fieldname name for all the fields in the query.

You can always see the query being generated with this option:
'debugSql' => true,

For advanced search engines my recommendation would be you figure out exactly how you want it to work.
Write up a few short use cases (searching for 123X should show this result because it's related to table X
as a Y), and then have us or another programmer write up the SQL for you.
Dave Edis - Senior Developer
interactivetools.com