Advertisement
freddy0512

ajax search

Sep 8th, 2015
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.49 KB | None | 0 0
  1. //ajax jquery search om
  2. $("#button-box-1").click(function(event) {
  3.     //alert();
  4.     event.preventDefault();
  5.     //merk
  6.     var autocomplete = $(".autocomplete").val();
  7.     //tipe
  8.     var autocomplete1 = $(".autocomplete1").val();
  9.     $.ajax({
  10.         type: "POST",
  11.         url:site+'/welcome/searchproduct',
  12.         dataType: 'json',
  13.         data: {
  14.             autocomplete: autocomplete,
  15.             autocomplete1: autocomplete1
  16.          },
  17.         success: function(res) {
  18.         if (res)
  19.             {
  20.                $(".box-2").show()
  21.             }
  22.          }
  23.     });
  24. });
  25.  
  26.  
  27.  
  28.  
  29. <!--controller-->
  30. public function searchproduct()
  31.     {
  32.         //for post caming from
  33.         $autocomplete=$this->input->post('brand');
  34.        
  35.         $autocomplete1=$this->input->post('tipe');
  36.  
  37.         $this->db->select('*');
  38.         $this->db->from('li_product_post a');
  39.         $this->db->join('li_brand b', 'b.id_brand=a.id_brand', 'left');
  40.         $this->db->join('li_tipe c', 'c.id_tipe=a.id_tipe', 'left');
  41.                 //or where
  42.         $this->db->where('name_brand', $autocomplete);
  43.         $this->db->or_where('name_tipe', $autocomplete1);
  44.  
  45.         $query = $this->db->get();
  46.  
  47.         foreach($query->result() as $row)
  48.         {
  49.             $arr['query'] = $keyword;
  50.             $arr['suggestions'][] = array(
  51.                 'value' =>$row->name_tipe,
  52.                 'id_brand'  =>$row->id_brand,
  53.                 'id_tipe'   =>$row->id_tipe,
  54.                 'product_harga' =>$row->product_harga,
  55.                 'product_toko'  =>$row->product_toko,
  56.                 'product_status'    =>$row->product_status,
  57.             );
  58.  
  59.         }
  60.         echo json_encode($arr);
  61.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement