Filter / Search
3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 3, 2011 (RSS)
By Toledoh - March 2, 2011
Hi Guys.
I've got a simple table on a list viewer page.
I've included the following search code at the top of the table with the aim of filtering the table by "tag".
The tag is a multi-select list.
I'm having 2 issues.
1. If a record has picked the tags "builder" and "plumber", the select option show a single option as "builderplumber". How do I get these as separate choices?
2. The submit results in a page of results, however that page shows the filter with the drop down consisting of only the item I chose, not the full list of tags. Whats the best way of handling this? I could go to a jQuery function, but the client really hasn't paid for that level of functionality.
I've got a simple table on a list viewer page.
I've included the following search code at the top of the table with the aim of filtering the table by "tag".
The tag is a multi-select list.
I'm having 2 issues.
1. If a record has picked the tags "builder" and "plumber", the select option show a single option as "builderplumber". How do I get these as separate choices?
2. The submit results in a page of results, however that page shows the filter with the drop down consisting of only the item I chose, not the full list of tags. Whats the best way of handling this? I could go to a jQuery function, but the client really hasn't paid for that level of functionality.
<?php
$group = array();
foreach ($business_directoryRecords as $record){
$group[$record['tags']]=$record['tags'];
}
?>
<form method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<input type="text" name="title,name_keyword" value="">
<select name="tags">
<option value="">select</option>
<?php foreach($group as $tags): ?>
<option value="<?php echo $tags;?>"><?php echo $tags;?></option>
<?php endforeach?>
</select>
<input type="submit" name="submit" value="Search">
</form>
Cheers,
Tim (toledoh.com.au)
Tim (toledoh.com.au)
Re: [Toledoh] Filter / Search
By Jason - March 3, 2011
Hi Tim,
I think the issue here is that tags is a string of values separated by tags. If you want to output each selection as a different option, you'll need to break that string up into an array and then output those one at a time:
Try this:
Depending on how you're using the selected value, you may need to change how you're doing your search to create the where clause manually. You could try something like this:
As for your second question, are you only getting back one drop down options, ie the option previously selected? If so, I think you're best bet is to do a separate select query to get your tags options, and not use the returned records to get your list.
Hope this helps get you started.
I think the issue here is that tags is a string of values separated by tags. If you want to output each selection as a different option, you'll need to break that string up into an array and then output those one at a time:
Try this:
<?php
$group = array();
foreach ($business_directoryRecords as $record){
$group[$record['tags']]=$record['tags'];
}
?>
<form method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<input type="text" name="title,name_keyword" value="">
<select name="tags">
<option value="">select</option>
<?php foreach($group as $tags): ?>
<?php $tagList = explode( "\t", trim( $tags, "\t" )); ?>
<?php foreach ($tagList as $tag ): ?>
<option value="<?php echo $tag;?>"><?php echo $tag;?></option>
<?php endforeach ?>
<?php endforeach?>
</select>
<input type="submit" name="submit" value="Search">
</form>
Depending on how you're using the selected value, you may need to change how you're doing your search to create the where clause manually. You could try something like this:
<?php
$where = "0";
if(@$_REQUEST['title,name_keyword']){
$escapedValue = mysql_escape (@$_REQUEST['title,name_keyword']);
$where = " OR title LIKE '%$escapedValue%' OR name LIKE '%$escapedValue%'";
}
if(@$_REQUEST['tags']){
$where .= " OR tags LIKE '%\t".mysql_escape(@$_REQUEST['tags'])."\t%'";
}
list($business_directoryRecords , $business_directoryMetaData) = getRecords( array(
'tableName' => 'business_direcotry',
'where' => $where,
'allowSearch' => false,
));
?>
As for your second question, are you only getting back one drop down options, ie the option previously selected? If so, I think you're best bet is to do a separate select query to get your tags options, and not use the returned records to get your list.
Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
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] Filter / Search
By Toledoh - March 3, 2011
Thanks Jason.
The first part worked a treat.
I couldn't get the 2nd bit to work, but that's fine, I'll just to a results page.
The first part worked a treat.
I couldn't get the 2nd bit to work, but that's fine, I'll just to a results page.
Cheers,
Tim (toledoh.com.au)
Tim (toledoh.com.au)