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: [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: [jimbly2] Setting a custom search....

By Dave - January 10, 2008

So you want like a "keyword" field? What press release fields do you want searched for the keyword? (title, content, etc?)

It shouldn't be that hard at all. It's very similar to how we did the other search fields. Let me know the fields you want searched and I'll write something up for you.
Dave Edis - Senior Developer
interactivetools.com

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 :-)