search database from multiple dropdownlist using php

somebody pls help me...
i'm very new in php...i have a problem when search database using multiple dropdownlist...
i call so many function like below to search
....either user select one dropdown list..
either two dropdownlist and all selected...
how can i combine all together in one function?call one function only whatever selection that user made..

some part in html:


......



.......



...........



some part in php...

if (isset($_POST['submit'])) {

if ($_POST['Location'] && $_POST['Subject'] && $_POST['Semester'] ){

.....
$staff=$staff->getLecturers_Loc_Sub_Sem($_POST['Location'],$_POST['Subject'],$_POST['Semester']);}

else if ($_POST['Location'] && $_POST['Subject']){

.......
$staff=$staff->getLecturers_Loc_Sub($_POST['Location'],$_POST['Subject']); }

else if ($_POST['Location'] && $_POST['Semester']){

...........
$staff=$staff->getLecturers_Loc_Sem($_POST['Location'],$_POST['Semester']); }

else if ($_POST['Subject'] && $_POST['Semester']){

.......
$staff=$staff->getLecturers_Sub_Sem($_POST['Subject'],$_POST['Semester']); }

else if ($_POST['Location']){

.............
$staff=$staff->getLecturers_Loc($_POST['Location']); }

else if ($_POST['Subject']){

..............
$staff=$staff->getLecturers_Sub($_POST['Subject']); }

else if ($_POST['Semester']){

...........
$staff=$staff->getLecturers_Sem($_POST['Semester']); }

some sql statement when search location and subject in this function...

getLecturers_Loc_Sub($id1,$id2); {
....
$sql= "select * from intake i,intake_subject ij, staff_subject ss
where i.location=$id and ss.subject=$id2
and i.id=ij.intake and ij.subject=ss.subject group by ss.staff";
.....
}

Comments

  • Can't you give them default values?[code]function getLecturers($id1=0,$id2=0,$id3=0)
    {...
    }

    if(isset($_POST['submit']))
    {/*$staff=*/$staff->getLecturers($_POST['Location'],$_POST['Subject'],$_POST['Semester']);
    }[/code]and I dunno why you must return something to the Class.
  • : Can't you give them default values?[code]function getLecturers($id1=0,$id2=0,$id3=0)
    : {...
    : }
    :
    : if(isset($_POST['submit']))
    : {/*$staff=*/$staff->getLecturers($_POST['Location'],$_POST['Subject'],$_POST['Semester']);
    : }[/code]and I dunno why you must return something to the Class.
    :

    I solve those problems like this:
    [code]
    function getLecture($loc, $subject, $sem)
    {
    // I don't know your table structure so I call my fileds Location, Subject and Semester
    $sql = 'SELECT * FROM my_list WHERE 1';
    if ($loc) $sql .= ' AND Location="'.$loc.'"';
    if ($subject) $sql .= ' AND Subject="'.$subject.'"';
    if ($sem) $sql .= ' AND Semester="'.$sem.'"';

    // you should always produce nice SQL
    $sql .= ';';

    $resul = mysql_query($sql); // or whatever API you use
    }
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories