SELECT with conditional WHERE parts


/ Published in: PHP
Save to your folder(s)

Building a SELECT with conditional WHERE parts, given from form-get parameters.


Copy this code and paste it in your HTML
  1. $selsearch = '
  2. SELECT
  3. Uni,Prof,Bearbeiter,Jahr,Semester,ID,Thema,status
  4. FROM
  5. Habilitation
  6. WHERE 1 ';
  7.  
  8. if ( strlen($_GET["uni"])>0 ) { $selsearch .= ' AND Uni LIKE "'.$_GET["uni"].'%" '; }
  9. if ( strlen($_GET["jahr"])>0 ) { $selsearch .= ' AND jahr LIKE "'.$_GET["jahr"].'%" '; }
  10. if ( strlen($_GET["thema"])>0 ) { $selsearch .= ' AND Thema LIKE "%'.$_GET["thema"].'%" '; }
  11.  
  12. $selsearch .= ' ORDER BY '.$o.' LIMIT '.$posSelect.','.$perpage;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.