2016-04-23 11 views
1

Ich werdeErstellen Sie einen Filter mit einem Multiple Input Codeigniter

hier ist mein Modell

<?php 
function show($branch,$department,$employee,$status,$from,$to,$category) 
{ 
    $this->db->select('a.*,b.name,c.cityname'); 
    $this->db->from('expreport a'); 
    $this->db->join('expuser b','a.createdby=b.unique_id'); 
    $this->db->join('expcity c','a.cityid=c.citycode'); 

    if($branch != "" || $status !="" || $from !="" || $to !="" || $department !="" || $employee !="") 
    { 
    $this->db->select('d.employeename,e.branchname,f.deptname'); 
    $this->db->from('expemployee d'); 
    $this->db->join('expbranch e','d.branchid=e.branchcode'); 
    $this->db->join('expdepartment f','d.deptid=f.deptcode'); 
    $this->db->like('branchid', $branch); 
    $this->db->or_like('deptid', $department); 
    $this->db->or_like('employeeid', $employee); 
    $this->db->where('status', $status); 
    $this->db->where('fromdate <=',$from); 
    $this->db->where('todate >=',$to); 
    } 

    if($category !="") 
    { 
    $this->db->select('g.category'); 
    $this->db->from('expcategory g'); 
    $this->db->like('catcode', $category); 
    } 

    $this->db->group_by('reportcode'); 
    $result = $this->db->get(); 
    echo $this->db->last_query(); 
    return $result->result(); 
} 
?> 

Ich habe 7 Eingänge in Sicht, Ich will die $ Zweig trennen, $ status einen Filter erstellen , $ from, etc, So können die Abfragen von nur 1 Variable ausführen, also muss ich nicht alle Variablen eingeben, denn wenn ich nur 1 Eingabe füllen, führen die Abfragen nicht aus

Alle Antworten werden geschätzt , Danke :)

+0

Verwendung nur einzelne Datenvariable $ in Funktionsparameter, wenn Sie von den Controller $ data Funktion übergeben zu [ 'Niederlassung']. –

+0

können Sie ein paar Beispiele geben? @AmitChauhan –

+0

also sollte ich 7 Funktionen im Modell machen ?? und einmal Funktionen enthalten Abfragen pro Eingabe? –

Antwort

0

Ich habe etwas ähnliches getan. Ich habe eine Datenfilterung basierend auf zwei Filtern. Ich habe Kategoriefilter und Standortfilter. Es ist in Tschechisch, aber die erste Reihe von Radiobuttons ist Kategorie und die zweite Reihe ist Standort.

enter image description here

// After user hits "Show events"  
if($submit == "Submit"){ 
    //check if category filter was applied 
    if(isset($category_filter) && $category_filter!='' && $category_filter!='everything'){ 
     //Add category number into variable and then into SQL query 
     $cat_sql_condition = 'AND category='.$category_filter.''; 
    }else{ 
     $cat_sql_condition=''; 
    } 
    //check if location filter was applied 
    if(isset($location_filter) && $location_filter!='' && $location_filter!='everything'){ 
     $loc_sql_condition = 'AND location_id='.$location_filter.''; 
    }else{ 
     $loc_sql_condition=''; 
    } 
    //Here i am creating the final query 
    $query_string = "SELECT * FROM tbl_events WHERE visibility=1 AND start_date> ".$current_unix_timestamp." ".$cat_sql_condition." ".$loc_sql_condition." ORDER BY start_date;"; 
}else{ 
    //Without submit 
    $query_string = "SELECT * FROM tbl_events WHERE visibility=1 AND start_date>'.$current_unix_timestamp.' ORDER BY start_date"; 
} 
Verwandte Themen