Search

5 posts by 3 authors in: Forums > CMS Builder
Last Post: December 28, 2012   (RSS)

Hi Greg,

If your using the get_records function to return your search results, you can use the keywords search field format to return parts of words. You can read more on it here:

http://www.interactivetools.com/docs/cmsbuilder/viewer_search.html

Here is an example of how you might implement it:

===============================================

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?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('C:/wamp/www/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records from 'blog' search has been set to true.
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'loadUploads' => true,
'allowSearch' => true,
));

?>

=======================================================

<!-- This search form will return any entries which contain the searched word in the title. -->
<form action="?" method="get" >
<input type="text" name="title_keyword" value="" />
<input type="submit" name="submit" value="Search!" />
</form>

<!-- display all/search results -->

<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<h1>Blog - List Page Viewer</h1>
<?php foreach ($blogRecords as $record): ?>
Record Number: <?php echo htmlencode($record['num']) ?><br/>
Title: <?php echo htmlencode($record['title']) ?><br/>
Date: <?php echo date("D, M jS, Y g:i:s a", strtotime($record['date'])) ?><br/><!-- For date formatting codes see: http://www.php.net/date -->
Content: <?php echo $record['content']; ?><br/>
jhgjhg (value): <?php echo $record['jhgjhgjhgjhg'] ?><br/>
jhgjhg (label): <?php echo $record['jhgjhgjhgjhg:label'] ?><br/>
_link : <a href="<?php echo $record['_link'] ?>"><?php echo $record['_link'] ?></a><br/>

<!-- STEP 2a: Display Uploads for field 'uploads' (Paste this anywhere inside STEP2 to display uploads) -->
<!-- Upload Fields: extension, thumbFilePath, isImage, hasThumbnail, urlPath, width, height, thumbUrlPath, thumbWidth, thumbHeight, info1, info2, info3, info4, info5 -->
Uploads:
<blockquote>
<?php foreach ($record['uploads'] as $index => $upload): ?>
Upload Url: <?php echo $upload['urlPath'] ?><br/>

<!-- Uploads: Copy the tags from below that you want to use, and erase the ones you don't need.

Thumb Url: <?php echo $upload['thumbUrlPath'] ?><br/><br/>
Download Link: <a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/><br/>

Image Tags:<br/>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>

info1 (Title) : <?php echo htmlencode($upload['info1']) ?><br/>
info2 (Caption) : <?php echo htmlencode($upload['info2']) ?><br/><br/>

Extension: <?php echo $upload['extension'] ?><br/>
isImage: <?php if ($upload['isImage']): ?>Yes<?php else: ?>No<?php endif ?><br/>
hasThumbnail: <?php if ($upload['hasThumbnail']): ?>Yes<?php else: ?>No<?php endif ?><br/>
<hr/>
// end uploads comment tag -->

<?php endforeach ?>
</blockquote>
<!-- STEP2a: /Display Uploads -->

<hr/>
<?php endforeach ?>

===============================

Thanks

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Hi Gregs,

Unless I've missed something, using the example you gave, if "widget" is entered,  the search code will return any title that contains the word "widget", so it will return records with things like xwidget and widgets and abcwidgetxyz in the title.

However, if "widgets" is entered as the search term, none of the above will be returned because none of them contains the word "widgets" (plural), which is only answers half of the question.

I saw suggestions for implementing the "like" function with wildcards, but I'm not sure how to do that and think it would cause other issues.

Not all words are pluralized by adding an (s) to the end of them ( party, parties) and simple words like "car" or "cars" might generate many unwanted results that contain the words car or cars.

There might have to be grammatical rules about lengths and ending S letters to sort things out, but even then, not all queries would necessarily be returned as desired.

Just my thoughts...

Best,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Hi guys,

Thanks for your messages!

I now see that the problem is not with the search keyword function that I am using. The problem is because there is no mention of "widgets" in my `cms_listings` table, which is the table being searched. All listings are simply labelled as "widget 100" or "widget 200".

"widgets" is however used as a category name, which is stored in a different table and I would like to be able to return all results from the "widgets" category or simply a link to the "widgets" category.

So I guess my next question is how can I have one search textfield that can return results from multiple tables... is that possible? Or is there a workaround you can suggest?

Thanks again,

Greg

Hi Greg,

Do  a search on the forum for multisearch

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php