Welcome Guest, Not a member yet? Register   Sign In
passing input value from view to model
#1

Hi,I'm new to CI and running on 3.1.9.

Was trying to create a previous/next button function when scrolling through some rows of data,by referring to infoID textbox as reference.

This is my example table:

Code:
infoID   userNAME
1         Alpha
2         Bravo
3         Charlie
4         Delta
5         Echo


This is part of my view:
Code:
<form method="" action="<?php echo base_url() ?>index.php/main_ctlr/next_info">
<button id="next" type="submit" style="width:10%" >NEXT</button>
</form>

<p>ID: <input type="text" name="infoID" style="width:200px" readonly value="<?php echo $infoID;?>"/></p>
<p>NAME: <input type="text" name="userNAME" style="width:200px" value="<?php echo $userNAME;?>"/></p>


This is part of my controller:

Code:
public function index()    {        
        $info = $this->info_model->get_first_info();
        $data['infoID'] = $info['infoID'];
        $data['userNAME'] = $info['userNAME'];
        $this->load->view('main_page', $data);
}

public function next_info() {            
        $info = $this->info_model->get_next_info();
        $data['infoID'] = $info['infoID'];
        $data['userNAME'] = $info['userNAME'];
        $this->load->view('main_page', $data);
}

This is part of my model:
Code:
public function get_first_info() {
        $this->db->order_by('infoID', 'ASC', 1);
        $query = $this->db->get('info');
        return $query->row_array();  
 }

public function get_next_info() {
        $abc = $this->input->post('infoID');
        $this->db->where('infoID>', $abc);        
        $query = $this->db->get('info');                 
        return $query->row_array();            
 }

I have no problem loading the initial view,get first row of data,last row of data BUT facing issue when running the next row of data.

If I substitute $abc with a integer(since it's refer to an numeric id),example 2,i will able to display the data which the infoID is more than 2,such as 3.

What im trying to do is next row of data will refer to the current ID input textbox,such as row 3 will be shown if current input value is 2 and row5 will be shown if current input value is 4.

Anything that I'm missing here?
Reply


Messages In This Thread
passing input value from view to model - by Leolabs - 07-06-2018, 10:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB