Setting a custom search....

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

By jimbly2 - January 7, 2008

Hi - I have a page that will list all jobs under the job type 'Ventures' which I would like to be displayed as a default when the page loads.



I tried this:



// create custom where query
$type = "Ventures";
if ($country) { $where .= "location = '" .escapeMysqlString($country). "'"; }
if ($where && $type) { $where .= " AND "; }
if ($type) { $where .= "type = '" .escapeMysqlString($type). "'"; }

..but it gives an error message :

Notice: Undefined variable: where in C:\inetpub\wwwroot\camco_php\careers_ventures.php on line 290

Notice: Undefined variable: where in C:\inetpub\wwwroot\camco_php\careers_ventures.php on line 291
No records were found!

Can you tell me what I need to change please?



Thanks! Jim

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

By Dave - January 7, 2008

Sure, no problem.

The .= operator means "add to the end" or "append" so you're likely getting those errors because you're trying to add to a variable that hasn't been defined yet. Try defining $where with a blank value first like this so it's defined:

$where = "";

Then, you can use an if statement to assign a default value if there is no type defined. Like this:

if ($type == "") { $type = "Ventures"; }

Hope that helps, let me know if you need more detail.
Dave Edis - Senior Developer
interactivetools.com

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

By jimbly2 - January 7, 2008

Hi Dave,



still can't seem to get rid of the undefined variables....here's what I have now:

<?php
require_once "C:/inetpub/wwwroot/camco_php/cmsAdmin/lib/viewer_functions.php";
$options = array(); // NOTE: see online documentation for more details on these options
// get page number and keywords
$pageNumber = @$FORM['page'] ? $FORM['page'] : 1;
$country = @$FORM['location'];
$type = @$FORM['type'];

// create custom where query
$type = "Ventures";
if ($country) { $where .= "" .escapeMysqlString($country). "'"; }
if ($where && $type) { $where .= ""; }
if ($type == "") { $type = "Ventures"; }

$options['tableName'] = 'jobs'; // (REQUIRED) MySQL tablename to list record from. Example: 'article';
$options['titleField'] = 'title'; // (optional) MySQL fieldname used in viewer url for search engines. Example: 'title' would display: viewer.php/article_title_here-123
$options['viewerUrl'] = 'jobsPage.php'; // (optional) URL of viewer page. Example: '/articles/view.php';
$options['perPage'] = ''; // (optional) The number of records to display per page. Example: '5'; Defaults to 10.
$options['orderBy'] = 'title'; // (optional) Fieldnames to sort by. Example: 'field1, field2 DESC, field3';
$options['pageNum'] = $pageNumber;
$options['where'] = $where;
$options['useSeoUrls'] = ''; // (ADVANCED) Set this to '1' for search engine friendly urls: view.php/123 instead of view.php?123 (not supported on all web servers, and viewerUrl must be absolute path such as '/path/viewer.php')
list($listRows, $listDetails) = getListRows($options);
// update page links
$pageLink = "{$_SERVER['PHP_SELF']}?country=" .urlencode($country). "&type=" . urlencode($type);
$listDetails['prevPageLink'] = "{$pageLink}&page={$listDetails['prevPage']}";
$listDetails['nextPageLink'] = "{$pageLink}&page={$listDetails['nextPage']}";
$listDetails['firstPageLink'] = "{$pageLink}&page=1";
$listDetails['lastPageLink'] = "{$pageLink}&page={$listDetails['totalPages']}";

...which bit have I got wrong?

Thanks

Jim

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

By Dave - January 7, 2008

Try replacing this:

// create custom where query
$type = "Ventures";
if ($country) { $where .= "" .escapeMysqlString($country). "'"; }
if ($where && $type) { $where .= ""; }
if ($type == "") { $type = "Ventures"; }


with this:

// set default type
if ($type == "") { $type = "Ventures"; }

// create custom where query
$where = "";
if ($country) { $where .= "location = '" .escapeMysqlString($country). "'"; }
if ($where && $type) { $where .= " AND "; }
if ($type) { $where .= "type = '" .escapeMysqlString($type). "'"; }


Let me know how that works out.
Dave Edis - Senior Developer
interactivetools.com

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

By jimbly2 - January 7, 2008

Hi Dave,



..no joy - still returns this:



Notice: Undefined variable: where in C:\inetpub\wwwroot\camco_php\careers_ventures.php on line 288

Notice: Undefined variable: where in C:\inetpub\wwwroot\camco_php\careers_ventures.php on line 289
No records were found!

These are lines 288/9:

if ($where && $type) { $where .= " AND "; }
if ($type) { $where .= "type = '" .escapeMysqlString($type). "'"; }

Help! Thnx :-)

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

By Dave - January 7, 2008

And you have this above those lines?

$where = "";

Can you just attach the viewer (careers_ventures.php) to your post and I'll run it locally and have a look.
Dave Edis - Senior Developer
interactivetools.com

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

By jimbly2 - January 7, 2008

Hi - sorry - once I put that back in above it's working fine -

Thanks for your help!

best,

Jim

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

By jimbly2 - January 10, 2008

Hi Dave,

on the same topic of setting up a custom search, I'd like to have a search option at the top of the page that displays the Press releases - so people can search through them. Is this hard to do?

thanks
Jim

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

By jimbly2 - January 10, 2008

Yes - thats exactly what I need - the fields to search would be:

Title, Depeartment. Location and Date

Thanks Dave :-)