Category Search box with dropdown

5 posts by 2 authors in: Forums > CMS Builder
Last Post: July 23, 2010   (RSS)

By design9 - July 23, 2010

Hello,
I have created a search page so the front end user can search by keyword or by category for our articles. The keyword coding is fine but I cannot seem to get the dropdown with category fields to work. I need some help to figure out what is wrong with the category search. I have attached my page with code.

Here is the live page:
http://www.charlotteparent.com/test/search/articlesearch.php

Thanks,
April
Attachments:

articlesearch.php 45K

Re: [apdance9] Category Search box with dropdown

By Jason - July 23, 2010

Hi April,

The problem is in your drop down box. For each of your <option> tags, you are only providing a label, not a value, so you're always providing an empty search to the page.

How to fix this depends on how your storing the article category in the article table (ie, are you using the category name, or the category number?).

Here's the code you should try to add for either instance (the changes have been highlighted in red):

If you store the category using the categories name:

<span class="bodytext">Search by Category:</span><br /><br />
<form method="post" action="../search/articlesearch.php" >
<select name="article_category">
<option value="">select</option>
<?php foreach ($article_categoryRecords as $record): ?>
<option value="<?php echo $record['name'];?>"><?php echo $record['name'] ?></option>
<?php endforeach ?>
</select>


If you store the article as a number:

<span class="bodytext">Search by Category:</span><br /><br />
<form method="post" action="../search/articlesearch.php" >
<select name="article_category">
<option value="">select</option>
<?php foreach ($article_categoryRecords as $record): ?>
<option value="<?php echo $record['num'];?>"><?php echo $record['name'] ?></option>
<?php endforeach ?>
</select>


Give that a try and let me know how that goes.

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: [apdance9] Category Search box with dropdown

By Jason - July 23, 2010

Hi April,

It looks as if your articles are storing the category by name. If you could email me your FTP details to jason@interactivetools.com, I can take a look.

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: [apdance9] Category Search box with dropdown

By Jason - July 23, 2010

Hi April,

I found the problem. First, it turns out that the articles table stores the categories name, not the number, so I switched the drop down options to reflect that. The reason it wasn't performing the search is that, for CMS Builder to perform an automatic search, the field name has to be the same as a field in the database, so I switched the name of the name of the <select> from "article_category" to "category".

Everything should be working fine now.

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/