Setting a custom search....
20 posts by 2 authors in: Forums > CMS Builder
Last Post: January 18, 2008 (RSS)
By Dave - January 10, 2008
interactivetools.com
Re: [Dave] Setting a custom search....
By jimbly2 - January 10, 2008
By Dave - January 10, 2008
<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!
interactivetools.com
Re: [Dave] Setting a custom search....
By jimbly2 - January 12, 2008
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
<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
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!
interactivetools.com
Re: [Dave] Setting a custom search....
By jimbly2 - January 15, 2008
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!
interactivetools.com
Re: [Dave] Setting a custom search....
By jimbly2 - January 18, 2008
sorry - I'm being dim here - could you explain how I create another list viewer?
thanks
Jim