php - Using multiple select boxes to filter MySQL data -



php - Using multiple select boxes to filter MySQL data -

i have table echo'd php displays data. i'm trying info filter based on dropdowns , submit button. each individual dropdown query works 100%...just on own without elseif. i.e. if test them 1 1 , comment out others filter works, not when they're uncommented. here's code:

if ($_post['racename']!="select race") { $racename = mysqli_real_escape_string($mysqli, $_post["racename"]); $filter = "select a.membershipid, a.firstname, a.surname, t.raceid, t.time, r.raceid, r.racename, r.distance, r.clubyear athlete inner bring together time t on a.membershipid=t.membershipid inner bring together race r on t.raceid=r.raceid r.racename= '$racename' order a.surname"; } elseif ($_post['athlete']!="select athlete") { $athlete = mysqli_real_escape_string($mysqli, $_post["athlete"]); $firstword = explode(' ',trim($athlete)); $firstname = $firstword[0]; $lastword = explode(' ', $athlete); $surname = array_pop($lastword); $filter = "select a.membershipid, a.firstname, a.surname, t.raceid, t.time, r.raceid, r.racename, r.distance, r.clubyear athlete inner bring together time t on a.membershipid=t.membershipid inner bring together race r on t.raceid=r.raceid a.firstname= '$firstname' , a.surname = '$surname' order a.surname"; } elseif ($_post['distance']!="select distance") { $distance = mysqli_real_escape_string($mysqli, $_post["distance"]); $filter = "select a.membershipid, a.firstname, a.surname, t.raceid, t.time, r.raceid, r.racename, r.distance, r.clubyear athlete inner bring together time t on a.membershipid=t.membershipid inner bring together race r on t.raceid=r.raceid r.distance= '$distance' order a.surname"; } elseif ($_post['clubyear']!="select club year") { $clubyear = mysqli_real_escape_string($mysqli, $_post["clubyear"]); $filter = "select a.membershipid, a.firstname, a.surname, t.raceid, t.time, r.raceid, r.racename, r.distance, r.clubyear athlete inner bring together time t on a.membershipid=t.membershipid inner bring together race r on t.raceid=r.raceid r.clubyear= '$clubyear' order a.surname"; } else { $filter = "select a.membershipid, a.firstname, a.surname, t.raceid, t.time, r.raceid, r.racename, r.distance, r.clubyear athlete inner bring together time t on a.membershipid=t.membershipid inner bring together race r on t.raceid=r.raceid order a.surname"; } $result = $mysqli->query($filter);

as can see i'm combining them elseif's because have intention of combining queries user can utilize number of dropdowns filter. right i'd each 1 work on own using elseif method. @ moment, code works racename, nil else. returns blank table. ideas?

because first bit of code runs doesn't elseif's. seek switch statement instead, or take out else's

php mysql

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -