PHP and MySQL user filtering -


i have web application shows list of events taken mysql db , presented user.

the user can filter results according several (8-10) 'types'

my question is, how should approach this? need take user input filter (in $_get) , find out types looking filter , according that, change sql query.

how do in way not complex? thought of using many 'if' or 'case' statements, i'm not sure if that's best solution lot of coding simple thing..

can give me advice? thanks,

example db:

event_id    event_name     event_type 1           test           regular 2           test2          vip 3           test4          testtype 

...

example $_get:

$_get['regular'] = 'on' 

...

you should create array of types using checkboxes

<input type="checkbox" name="types[]" value="regular" /> regular  <input type="checkbox" name="types[]" value="vip" /> vip 

then have array of types $_request['types']...

echo implode(",",$_request['types]); // example

well depends if store event_types string (you shouldnt).

if change them int do

$query = "select * events";  if(isset($_request['types'])){     $query .= "and event_types in (".implode(",",$_request['types']).")"; } 

if keep them string in db same thing you'll have had '' around values...

of course you'll have secure this


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -