Jump to content

skemi90

New Members
  • Posts

    6
  • Joined

  • Last visited

skemi90's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Scootash WERE ARE YOU YESTERDAY???? Just joking, big thanks! For others, maybe someone will have a simmilar problem. In controller add a function: public function search() { $data['test'] = $this->Test_model->get('id', 'DESC', 10); $this->load->view('home/test1', $data); } On page (test1) echo the json result (echo $test;) And in view for test, change var json to that new function search in controller: var json = '<?= site_url('test/search');?>'; And you have a simple json live search. Thanks again scootash!!!
  2. Hi, I have a problem with $.getJSON function. I am using Codeigniter.My main problem is in view. In console, when typing in search input, I get error 403 forbiden, but variable $test is geting json parameters from database. I am a beginner in jquery. Main goal for this is to make a live search with json. Thanks in advance for any help. Controller code: class Test extends CI_Controller{ public function index() { $data['test'] = $this->Test_model->get('id', 'DESC', 10); $this->load->view('home/inc/header_view'); $this->load->view('home/test',$data); $this->load->view('home/inc/footer_view'); } } Model code: <?php class Test_model extends CI_Model { public function get($order_by = null, $sort = 'DESC', $limit = null, $offset = 0) { $this->db->select('*'); $this->db->from('prevoznici'); if ($limit != null){ $this->db->limit($limit, $offset); } if ($order_by != null){ $this->db->order_by($order_by, $sort); } $query = $this->db->get(); return json_encode($query->result()); } } View Code (mix of php and javascript): <div id="searcharea"> <label for="search">Search</label> <p>Enter name</p> <input id="search" type="search" name="search" placeholder="Name or info"> </div> <div id="update"></div> <script src="<?= site_url()?>public/js/jquery.js"></script> <script src="<?= site_url()?>public/js/jqueryjsonp.js"></script> <script type="text/javascript"> $('#search').keyup(function(){ var searchField = $('#search').val(); var myExp = new RegExp(searchField, "i"); var json = '<?= $test;?>'; $.getJSON(json, function(data){ var output = '<ul class="searchresults" >'; $.each(data, function(key, val){ if((val.naziv.search(myExp) != -1) || (val.datum.search(myExp) != -1)) { output += '<li>'; output += '<h2>' + val.naziv + '</h2>'; output += '<p>' + val.datum + '</p>'; output += '</li>'; } }); output += '</ul>'; $('#update').html(output); }).error(function() { alert("error"); }); }); </script>
  3. This topic is SOLVED! I was loking a way to mark it by myself, but without luck. Please, can any moderator mark this topic as SOLVED?
  4. Guys, thank you very much!!! I managed to solve the problem. The function is now working. The problem was the lack of foreach loop. (Thanks Muddy_Funster) Thank you again!
  5. Model public function GET($input1, $input2){ $this->db->select('c'); $this->db->from('table1'); $this->db->where('A', $input1); $this->db->where('B', $input2); $query = $this->db->get(); return $query; } Controller public function get_result() { //validation rules $this->form_validation->set_rules('a', 'A', 'trim|required'); $this->form_validation->set_rules('b', 'B', 'trim|required'); if ($this->form_validation->run() == FALSE) { $this->load->view('admin/dashboard/inc/header'); $this->load->view('admin/procena/index'); $this->load->view('admin/dashboard/inc/footer'); } else { $input1 = $this->input->post('A'); $input2 = $this->input->post('B'); $result = $this->ModelABC_model->GET($input1,$input2); echo $result; /*redirect('admin/index');*/ } } At least now I'm going in a certain direction, I think I understand your logic but now I have a new problem. I get an error "could not be converted to string" Thank you for your rapid response.
  6. Hello, I am new to php and I am stuck with this problem. I have in my mysql base a table (table1) with three columns A, B and C (for easy explanation). id A B C 1 60 200 4 2 40 100 3 ... ... ... ... Table has more than 500 combinations. I created two input fields on my index page for column A and B. C column is a result. Problem is to code next: When someone enters 60 and 200 in those two input fields I want to generate an automatic result 4, for 40 and 100 result 3 and so on. I am using codeigniter framework. If it is needed you can split above table to three tables A, B and C. Thanks in advance and sorry for my bad english, please don't hesitate to ask questions.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.