Posted By

assbach on 12/15/06


Tagged

mysql select sql php where


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

vali29


SELECT with conditional WHERE parts


 / Published in: PHP
 

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

  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  

You need to login to post a comment.