Search Engine and List Page Display

9 posts by 2 authors in: Forums > CMS Builder
Last Post: April 19, 2011   (RSS)

By JLynne77 - April 14, 2011

Hello, all,

I'm working on a doctors database. The list currently displays automatically in alphabetical order when I load the list page. At the top of the page, I have several options to narrow those results down via the built-in search functions.

However, any time a user lands on that initial page, they see the same set of doctors. As you can imagine, those doctors are going to get a lot of hits from people who are too lazy to use the search engine. That doesn't sit well with the other doctors.

What I'm trying to do is set the page to show as blank with only the search options when you first land on it, and then display results to the search only when options are picked. This way, all the doctors of a certain search result have a fair shot at being seen instead of some doctors always being seen on a landing page before a search is even entered.

Is there a way for me to use an if statement to check the search options to see if there was a value entered? That way, if there is no value, it would load a blank page, but, if there is a value, it would load the results of that value.

Thank you in advance!
-----
~Jessica Sullivan, Crystal Realm Designs.

Re: [Duches77] Search Engine and List Page Display

By Jason - April 14, 2011

Hi Jessica,

Yes, a good way to do this is to put your query inside an if statement checking for a value in the $_REQUEST array. I usually use a hidden field that I call "formSubmitted" to detect whether or not they've done the search.

Here is an example of how it could work. In your form, you would have something like this:

<form method="post" name = "doctorSearch" action = "?" >
<input type = "hidden" name = "formSubmitted" value = "1" />


Then up at the top of your page you could do this:

if (@$_REQUEST['formSubmitted']) {

list ($doctorRecords, $doctorMetaData) = getRecords(array(
'tableName' => 'doctors',
));
}
else {

$doctorRecords = array();
}


That way when they go to this page, if they haven't used your form, no records will be returned.

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 Engine and List Page Display

By JLynne77 - April 14, 2011

Wow, that's even easier than my original idea.

Addionally, if I link to the same listing page with the search query in the URL, will it display the listings without submitting the form? or will I need to add "formSubmitted=1" to the URL as well?
-----
~Jessica Sullivan, Crystal Realm Designs.

Re: [Duches77] Search Engine and List Page Display

By Jason - April 14, 2011

Hi Jessica,

In this example, you would need to add "formSubmitted" to the URL. If this is something you need to do frequently, you can remove formSubmitted and use:

if ($_REQUEST) {

instead. This just checks to see if there's something in the request array, it doesn't matter what's in there. This would make it easier linking in from other pages, but doesn't guarantee that a form was submitted.

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 Engine and List Page Display

By JLynne77 - April 14, 2011 - edited: April 14, 2011

I seem to be hitting a block. I have:
if ($_REQUEST) {
// load records if there is a search variable
list($find_a_doctorRecords, $find_a_doctorMetaData) = getRecords(array(
'tableName' => 'find_a_doctor',
));

} else {
// or do not load any records
$find_a_doctorRecords = array();
}



I did not add the hidden field to the form as we're not using it. The page loads properly for no form selection and having the search keyword in the URL, but not when I select something from the search form. I get a blank page.

Page is here... The drop downs are the search form. The letter graphics are loading the search parameter from the URL.

edit updated code and page URL





edit2 for the sake of keeping my hours down for the sake of the client's billing, I've decided to use separate pages for the search form and the results list. Thank you for your help, though.
-----
~Jessica Sullivan, Crystal Realm Designs.

Re: [Duches77] Search Engine and List Page Display

By Jason - April 15, 2011

Hi Jessica,

Okay, I hope that works out for you. One thing I did notice, is that if you only selected from 1 drop down, you got result, but not when you selected from both. This is because selecting from both makes your search more restrictive, so it's more likely that you're not going to return a result. One this you can try is put your drop downs in separate forms, and put the words "OR" on your form so people know that they are searching for either one or the other.

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 Engine and List Page Display

By JLynne77 - April 15, 2011

The lack of results could be because, for testing, we do not have the entire Doctor's database entered into the system. I know which combinations will get results. If you pick "Internal Medicine" and "GHI", you'll get results. It's going to end up being a database of a couple hundred doctors, but I'm trying to get things to work before entering them all in. That way, if any changes have to be made to the way the CMS forms are set up, we don't have to go back and change several hundred doctors in case lists needed to be re-entered, but rather, only a small set. One thing I have noticed that can be quite tedious when you have a lot of records is that, when you edit anything in a list, you have to go back through and update the list selections for every single record.
-----
~Jessica Sullivan, Crystal Realm Designs.

Re: [Duches77] Search Engine and List Page Display

By Jason - April 18, 2011

Hi Jessica,

I am a little unsure of what you mean when you say you have to "update the list selections for every single record". Are you using a separate section to store your list? Are you referring to when you add a new record to a list, or when you change the name of something in the list?

If you're using a separate section for your list, a good practice is to use the "num" field as an option value. That way, if you ever go back into a record in your list and change anything, the num field will remain the same, so you won't have to update any records where that was selected.

Here are some instructions for setting that up:
http://www.interactivetools.com/forum/gforum.cgi?post=87356#87356

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/