search 2 or more keywords or words separated by a space

3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 15, 2014   (RSS)

By esupport - July 10, 2014 - edited: July 13, 2014

Hi ,

I would like to know if it possible to modify my code

so I can search 2 or more keywords or words separated by a space or another word or a DOT or an underscore or a (-) or a (+) or a (%) or (anything else lol).

Now only accept a keyword for searching.  If input 2 keywords.  It won't get result.

Search field code:

<form method="POST" action="searchResults.php">
<input name="title,intro_keyword" type="text" value="" size="16">
<input type="submit" name="submit" value="Search" class="btn">
</form>

searchResults.php - header

<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/quanmax/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'perPage' => '10',
'loadUploads' => true,
'allowSearch' => true,
));
?>

searchResult.php - Body

<table width="700" border="0" align="center" cellpadding="0" cellspacing="5">
<tr>
<td>Here are results of your search.</td>
</tr>
<tr>
<td> <?php foreach ($productsRecords as $record): ?>
</p>
<table border="0" cellspacing="0" cellpadding="0" width="700">
<span
id="news_list_lab">
<tbody>
<tr>
<td width="185" valign="top" class="content_s_000"><?php foreach ($record['images'] as $index => $upload): ?>
<img src="<?php echo $upload['thumbUrlPath2'] ?>" alt="<?php echo htmlencode($record['title']) ?>" width="<?php echo $upload['thumbWidth2'] ?>" height="<?php echo $upload['thumbHeight2'] ?>" hspace="20" /><br/>
<?php endforeach ?></td>
<td align="left" valign="top" class="content"><b> <a href="<?php echo 'products-detail.php?num='.$record['category'];?>"> <?php echo htmlencode($record['title']) ?> </a> </b> <?php echo $record['intro']; ?></td>
</tr>
<tr>
<td colspan="2" align="right" class="line_h_dot_black"><a href="<?php echo 'products-detail.php?num='.$record['category'];?>"><img
class="banner_line_no" hspace="0" alt="See More!" vspace="5"
src="images/share/button_more.gif" width="41"
height="11" /></a></td>
</tr>
</tbody>
</span>
</table>
<p>
<?php endforeach ?>
</td>
</tr>
</table>

Hope there is a simple way to get it.

Thanks!

Jax H.

-Jax H.

By esupport - July 15, 2014

Is anyone can help me improve?

Thanks!

-Jax H.

By claire - July 15, 2014

Hi JH

Take a look at these PHP functions: http://php.net/manual/en/function.explode.php and http://php.net/manual/en/function.implode.php

Explode will allow you to take the search string and split it into an array delineated by spaces, dots, whatever. From this, you should be able to modify your getRecords 'where' statement to include an implode that turns the array into a comma separated list.

This will let you search on multiple keywords.

--------------------

Claire Ryan
interactivetools.com

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