Filter / Search

3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 3, 2011   (RSS)

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:
<?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/

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.
Cheers,

Tim (toledoh.com.au)