Setting a custom search....

20 posts by 2 authors in: Forums > CMS Builder
Last Post: January 18, 2008   (RSS)

By Dave - January 10, 2008

Ok, did you want a single keyword field or multiple search fields? I ask only because searching the date field with a keyword probably wouldn't give the results you wanted. Do you want to search just "Title, Depeartment. Location" or something else?
Dave Edis - Senior Developer
interactivetools.com

By Dave - January 10, 2008

Ok, well the keyword search is pretty straightforward so lets start with that. Add a search form to the top, something like this:

<form method="get" action="<?php echo $_SERVER['PHP_SELF'] ?>">
Keyword: <input type="text" name="keyword" value="" size="15">
<input type="submit" name="" value="Search">
<input type="hidden" name="country" value="<?php echo @$FORM['country'] ?>">
<input type="hidden" name="type" value="<?php echo @$FORM['type'] ?>">
</form>


then your options code with this:

require_once "C:/inetpub/wwwroot/camco_php/cmsAdmin/lib/viewer_functions.php";

// set defaults
if (!@$FORM['type']) { $FORM['type'] = 'Ventures'; }
if (!@$FORM['page']) { $FORM['page'] = '1'; }

// create search conditions
$conditions = array();
if (@$FORM['country']) { $conditions[] = "location = '" .escapeMysqlString($FORM['country']). "'"; }
if (@$FORM['type']) { $conditions[] = "type = '" .escapeMysqlString($FORM['type']). "'"; }
if (@$FORM['keyword']) {
$escapedKeyword = escapeMysqlWildcards( escapeMysqlString($FORM['keyword']) );
$conditions[] = "(Title LIKE '%$escapedKeyword%' OR Department LIKE '%$escapedKeyword%' OR Location LIKE '%$escapedKeyword%')";
}
$where = join(' AND ', $conditions);

//
$options = array();
$options['tableName'] = 'jobs';
$options['titleField'] = 'title';
$options['viewerUrl'] = 'jobsPage.php';
$options['perPage'] = '';
$options['orderBy'] = 'title';
$options['pageNum'] = $FORM['page'];
$options['where'] = $where;
$options['useSeoUrls'] = '';
list($listRows, $listDetails) = getListRows($options);

// update page links
$pageLink = "{$_SERVER['PHP_SELF']}?location=" .urlencode(@$FORM['country']). "&type=" . urlencode(@$FORM['type']). "&keyword=" . urlencode(@$FORM['keyword']);
$listDetails['prevPageLink'] = "{$pageLink}&page={$listDetails['prevPage']}";
$listDetails['nextPageLink'] = "{$pageLink}&page={$listDetails['nextPage']}";
$listDetails['firstPageLink'] = "{$pageLink}&page=1";
$listDetails['lastPageLink'] = "{$pageLink}&page={$listDetails['totalPages']}";


Maybe create a copy of your original viewer (jobsList2.php) and try this there. Also, we're building a lot of this into the next version so it will be automatic and you won't have to add any code at all. But for now, this should work for you.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Setting a custom search....

By jimbly2 - January 12, 2008

Hi Dave - I can't get that to work at all :-(

It jus gives me a couple of error messages about undefined variables again. Is the reference to 'Ventures' needed? I wonder if this is throwing it out?

I have bought and downloaded the new version, but I'm nervous about upgrading halfway through a job....am I likely to lose a bunch of stuff. I have backed up the files you suggest...not sure how to back up the MySQL db though.

thanks
Jim

By jimbly2 - January 12, 2008

Just fyi - this is what I have on the page now:

<form method="get" action="<?php echo $_SERVER['PHP_SELF'] ?>">
Keyword: <input type="text" name="keyword" value="" size="15">
<input type="submit" name="" value="Search">
<input type="hidden" name="country" value="<?php echo @$FORM['country'] ?>">
<input type="hidden" name="type" value="<?php echo @$FORM['type'] ?>">
</form></p>
<p class="headings_camco">Press Releases</p>
<p class="bodycopy_bold"><!-- STEP1: Load Record (Paste this above other step) -->
<?php
require_once "C:/inetpub/wwwroot/camco_php/cmsAdmin/lib/viewer_functions.php";

// set defaults
if (!@$FORM['type']) { $FORM['type'] = 'Ventures'; }
if (!@$FORM['page']) { $FORM['page'] = '1'; }

// create search conditions
$conditions = array();
if (@$FORM['country']) { $conditions[] = "location = '" .escapeMysqlString($FORM['country']). "'"; }
if (@$FORM['type']) { $conditions[] = "type = '" .escapeMysqlString($FORM['type']). "'"; }
if (@$FORM['keyword']) {
$escapedKeyword = escapeMysqlWildcards( escapeMysqlString($FORM['keyword']) );
$conditions[] = "(Title LIKE '%$escapedKeyword%' OR Department LIKE '%$escapedKeyword%' OR Location LIKE '%$escapedKeyword%')";
}
$where = join(' AND ', $conditions);

//
$options = array();
$options['tableName'] = 'jobs';
$options['titleField'] = 'title';
$options['viewerUrl'] = 'jobsPage.php';
$options['perPage'] = '';
$options['orderBy'] = 'title';
$options['pageNum'] = $FORM['page'];
$options['where'] = $where;
$options['useSeoUrls'] = '';
list($listRows, $listDetails) = getListRows($options);

// update page links
$pageLink = "{$_SERVER['PHP_SELF']}?location=" .urlencode(@$FORM['country']). "&type=" . urlencode(@$FORM['type']). "&keyword=" . urlencode(@$FORM['keyword']);
$listDetails['prevPageLink'] = "{$pageLink}&page={$listDetails['prevPage']}";
$listDetails['nextPageLink'] = "{$pageLink}&page={$listDetails['nextPage']}";
$listDetails['firstPageLink'] = "{$pageLink}&page=1";
$listDetails['lastPageLink'] = "{$pageLink}&page={$listDetails['totalPages']}";
?>

<?php if ($record): ?>
Title:<br />
<span class="bodycopy"><?php echo $record['title'] ?></span><br/><br />

Department: <br />
<span class="bodycopy"><?php echo $record['department'] ?></span><br/><br />

Location: <br />
<span class="bodycopy"><?php echo $record['location'] ?></span><br/><br />

Date: <br />
<span class="bodycopy"><?php echo date("D, M jS, Y G:H:s a", strtotime($record['date'])) ?></span><br/><br />

<!-- For date formatting codes see: http://www.php.net/date -->
Content: <br />
<span class="bodycopy"><?php echo $record['content'] ?></span><br/><br /><br />


<?php endif ?>

<?php if (empty($record)): ?><!-- Display "No Records Found" Message -->
No record found!<br/><br/>
<?php endif ?>
<!-- STEP2: /Display Record -->



<!-- STEP3: Display Uploads from 'downloadPressRelease' (Paste this where you want your uploads displayed) -->
<!-- Upload Program Fields : num, createdTime, tableName, fieldName, recordNum, preSaveTempId, filePath, filename, extension, thumbFilePath -->
<!-- Upload Image Fields : isImage, hasThumbnail, urlPath, width, height, thumbUrlPath, thumbWidth, thumbHeight -->
<!-- Upload Info Fields : info1, info2, info3, info4, info5 -->
<?php foreach (getUploads($options['tableName'], 'downloadPressRelease', $record['num']) as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" /><br/>

<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" /><br/>

<?php else: ?>
<img src="images/icons/pdf.gif" alt="Downloadable pdf" width="30" height="31" /> <a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/>
<hr size="1" width="600" style="background-color:#e21937;color:#e21937"/>
<?php endif ?>
<?php endforeach ?>

By Dave - January 12, 2008 - edited: January 12, 2008

Hi Jim,

Just a side note, as a result of your requests, we've made these types of searches automatic in the latest version, so I want you to the know that the next project you do you won't have to mess with the code at all!

But for _this_ project we'll just do whatever we need to to get it working so you can wrap it up. It looks like the page had "page viewer" code instead of "list viewer" code. I've replaced the code that needed changing and attached a working version (let me know if it works on your end).

If that doesn't work let me know or you can always email me ftp and I can login and fix it up for you.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com
Attachments:

careers_ventures.php 4K

Re: [Dave] Setting a custom search....

By jimbly2 - January 15, 2008

Hi Dave,



sorry for late response - thanks very much for that. Does that mean I'm nearly famous? :-)

Am slightly nervouse about upgrading half way through my first job - ( lesson learnt the hard way!)

but have invested in the new versin and will update when this is over stage1.

Another question ( they never end ) if I want to have a list of just the titles of the press releases ( for example ) which can be viewed and then clicked on to go load the complete info....how would I do that?

Thanks -

Jim

By Dave - January 15, 2008

Another question ( they never end ) if I want to have a list of just the titles of the press releases ( for example ) which can be viewed and then clicked on to go load the complete info....how would I do that?


And you want this on another section of the site? Just create another "List Viewer" for the jobs and remove all the tags except "title" and "_link". Then change the 'viewerUrl' to point to the "page viewer" you already have.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Setting a custom search....

By jimbly2 - January 18, 2008

Hi Dave,

sorry - I'm being dim here - could you explain how I create another list viewer?



thanks

Jim

By jimbly2 - January 18, 2008

Sorted it :-)