Jump to content
Server Maintenance This Week. ×

Grouping Search Clauses with PHP


dph

This topic is 7324 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies

Hi there,

I'm trying to create a web page that searches multiple fields and returns a list of employees matching the search. Our database contains an archive of employees identified as terminated by a numeric field "Terminated". Basically I'm trying to see how one would go about achieving this SQL statement:

SELECT * FROM employees WHERE (firstname LIKE '%searchValue%' OR lastname LIKE '%searchvalue%' OR program LIKE '%searchvalue%' OR department LIKE '%searchvalue%') AND Terminated = 0

As there doesn't seem to be a way to add the necessary parentheses using FX for PHP, I tried adding the parameters in two ways as follows:

Try 1:

$EmpDB->AddDBParam('First Name',$theSearch,'cn');

$EmpDB->AddDBParam('-lop','or');

$EmpDB->AddDBParam('Last Name',$theSearch,'cn');

$EmpDB->AddDBParam('-lop','or');

$EmpDB->AddDBParam('Department',$theSearch,'cn');

$EmpDB->AddDBParam('-lop','or');

$EmpDB->AddDBParam('Program',$theSearch,'cn');

$EmpDB->AddDBParam('Terminated','0','eq');

Try 2:

$EmpDB->AddDBParam('First Name',$theSearch,'cn');

$EmpDB->AddDBParam('Terminated','0','eq');

$EmpDB->AddDBParam('-lop','or');

$EmpDB->AddDBParam('Last Name',$theSearch,'cn');

$EmpDB->AddDBParam('Terminated','0','eq');

$EmpDB->AddDBParam('-lop','or');

$EmpDB->AddDBParam('Department',$theSearch,'cn');

$EmpDB->AddDBParam('Terminated','0','eq');

$EmpDB->AddDBParam('-lop','or');

$EmpDB->AddDBParam('Program',$theSearch,'cn');

$EmpDB->AddDBParam('Terminated','0','eq');

Neither one of which worked because there is no way to force the logic that is required here. At this point I feel like I'm up a creek and missing my paddle. Anyone ever run into this?

Link to comment
Share on other sites

This topic is 7324 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.