1

I would like to do search for advanced search. The Search feature has and/or for every category. User can choose any combination of and n or. Here i give the screenshot

Advanced Search

I store the and/or into variable call $pil, $pil1,$pil2 and $pil3. And will put them in query. it's better than validate one by one every condition of and/or

So this is my query using postgresql in PHP

$query = pg_query("SELECT   evaluationdate,onlinename,channel,topik,reviewername,sourceevaluation,evaluation 
from AgentPerformance 
where onlinename like '%".$VEOn1."%'
".$pil." reviewername like '%".$VERev1."%' 
".$pil1." channel like '%".$VEChan1."%' 
".$pil2."sourceevaluation like '%".$VESource1."%'
".$pil3."evaluationdate between '".$VEStart1."' and '".$VEEnd1."'");

EDIT :

The problem now, All the variables must not be empty or the query will be error. any way to trick this?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Elbert
  • 516
  • 1
  • 5
  • 15

2 Answers2

2

You've missed some spaces near sourceevaluation and evaluationdate
Try with this query :

$query = pg_query("SELECT   evaluationdate,onlinename,channel,topik,reviewername,sourceevaluation,evaluation 
from AgentPerformance 
where onlinename like '%".$VEOn1."%'
".$pil." reviewername like '%".$VERev1."%' 
".$pil1." channel like '%".$VEChan1."%' 
".$pil2." sourceevaluation like '%".$VESource1."%'
".$pil3." evaluationdate between '".$VEStart1."' and '".$VEEnd1."'");
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Halayem Anis
  • 7,654
  • 2
  • 25
  • 45
0

Simply. Use validation for each $pil whether it is empty or not. it makes me validate 4 times, but it solves the problem. The syntax error has been solved too

Elbert
  • 516
  • 1
  • 5
  • 15
  • you can use this to verify `$pil1...$pilN` variables: `for($i=1 ; $i<4 ; $i++) { if (empty(${"pil" . $i})) { print "pil" . $i . " is empty "; } }` – Halayem Anis Dec 30 '15 at 07:54