Displaying the data dynamically using Ajax

前端 未结 5 442
难免孤独
难免孤独 2021-01-13 12:27

In this code, after clicking the like button, the data is added in the database already. What I wanted to do now is I would like after adding the data, I will query the tota

5条回答
  •  旧时难觅i
    2021-01-13 12:48

        public function article_search($search){
    
        $word = explode(' ',$search);   
    
        $query =  "select c.*,d.name,d.image_link from tbl_product as d inner join tbl_order as c on d.id=c.product_id
        where 1 and ";
        $i=1;
        foreach($word as $wd){
            if($i==1){
                $query.= "( c.customer like '%".$wd."%'";   
            }else{
                $query.=    " or c.customer like '%".$wd."%'";  
            }
            $i++;
        }
    
        foreach($word as $wd){
            if($i==1){
                $query.= "( c.order_no like '%".$wd."%'";   
            }else{
                $query.=    " or c.order_no like '%".$wd."%'";  
            }
            $i++;
        }
        foreach($word as $wd){
            if($i==1){
                $query.= "( d.name like '%".$wd."%'";   
            }else{
                $query.=    " or d.name like '%".$wd."%'";  
            }
            $i++;
        }
        foreach($word as $wd){
            if($i==1){
                $query.= "( d.commission like '%".$wd."%'"; 
            }else{
                $query.=    " or d.commission like '%".$wd."%'";    
            }
            $i++;
        }
        foreach($word as $wd){
            if($i==1){
                $query.= "( d.base_price like '%".$wd."%'"; 
            }else{
                $query.=    " or d.base_price like '%".$wd."%'";    
            }
            $i++;
        }
    
            $query.=    " or c.customer like '%".$search."%'";
            $query.=    " or c.order_no like '%".$search."%' ";
            $query.=    " or d.name like '%".$search."%' ";
            $query.=    " or d.commission like '%".$search."%' ";
            $query.=    " or d.base_price like '%".$search."%' )";
    
        $query = $this->db->query($query);
        //echo $this->db->last_query();die;
    
        $record = $query->result_array();
        foreach($record as $key=>$value){
            $cat       = $value['product_id'];
            $query_tag = $this->db->query("select * from tbl_product where  id in(".$cat.")");
            $record[$key]['all_pro'] = $query_tag->result_array();            
        }
        return $record;
    
    } 
    

提交回复
热议问题