Search from multiple fields in form

6 posts by 2 authors in: Forums > CMS Builder
Last Post: December 2, 2010   (RSS)

By 4cdg - November 19, 2010

Searching the forum for an answer but I have yet to find one that i think solves my issue.

I would like to search 1 table from a form that has multiple fields. Like the old listings manager would do, where each field corresponds to a db field and you have one submit button and the search returns any results of the fields that are filled in by the end user. So they could for example search a dropdown of categories, a price min max search and a text field where you input the city, hit submit and all three fields input are considered in the search results.

Also i would need user account table db info available because I would like to be able to search by Listed by (all items listed by a specific user -- like the old listings manager)

thanks

clay

Re: [4cdg] Search from multiple fields in form

By Jason - November 19, 2010

Hi Clay,

You can definitely do this. All you need to do is ensure that each of your form fields has the same name as the field in your table that you're searching against. So, for example, if you have a field in your section called "city" that you wanted to search against, your form field would look like this:

<input type="text" name="city" />

For your second issue, what you can do is use getRecords to select all the users from the accounts table and use this to populate a <select> box. The field in your table that you would want to search against is called createdByUserNum.

It would look something like this.

1) Get all the users from the database:
list($accountRecords,$accountMetaData)=getRecords(array(
'tableName' => 'accounts',
'allowSearch' => false,
));


Then use the result to populate your select box:

<select name="createdByUserNum">
<option value="">-Select-</option>
<?php foreach($accountRecords as $account): ?>
<option value="<?php echo $account['num'];?>"><?php echo $account['fullname'];?></option>
<?php endforeach ?>
</select>


This should get you started. Give this a try and if you're still having a problem, please attach both your search page and your search results page to this thread so I can see the code you're using.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Search from multiple fields in form

By 4cdg - November 30, 2010

Jason,

Search seems to be working great now. Just running into one issue. I need to search one more dropdown from the accounts field. it is called msba_region and it is a dropdown with 17 regions that each user chooses. i want to display all listings that are listed by someone in a certain region. How is that code different from the created by code?

here is my page. www.surplusprop.com/search.php

thanks

clay

Re: [Jason] Search from multiple fields in form

By 4cdg - December 2, 2010

jason,

everything is working great except for one thing. The msba region dropdown populates out of order. Kind of like the regions that have them most listings go to the top of the dropdown. I need them to show 1 - 17.

I have attached my search page
Attachments:

search_003.php 18K

Re: [4cdg] Search from multiple fields in form

By Jason - December 2, 2010

Hi,

A sort like this is getting a little more complicated than what we can accomplish in the forum. If you're interested in creating this, please send an email to consulting@interactivetools.com and we can go over some options with you.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/