Welcome Guest, Not a member yet? Register   Sign In
Update multiple rows in a table
#5

[eluser]eironotics[/eluser]
Hi mellis,

First of all thanks,to make it clearer to you heres my code.

please help me im completely new with CI.

Controller Contacts
Code:
class Contacts extends controller{
    
    function Contacts(){
        parent:: Controller();
        $this->load->database();
        
        $this->load->model('contacts_model');
        $this->load->helper('form');
        $this->load->scaffolding('contacts');
    ;
        }
    function index(){
        $data['title']="Displaying all Contacts";
        $data['query']=$this->contacts_model->poplist();
        $data['insert']=0;
        $this->load->view('contacts_view',$data);        
        }
    
    function popEditWindow(){
        //pass to array
        $arrayid= $this->input->post('edit');
        if(count($arrayid)){
            for($i=0;$i<=count($arrayid); $i++){
            //call model to compare
            $id= $arrayid[$i];
            echo $id;
            //call the view for display
            }
            }
        else{
            echo 'No selected';
            }
        
        }    
        
    function popInsertWindow(){
    
        $data['title']="Inserting New Contacts";
        $data['insert']=1;
        $this->load->view('contacts_view',$data);
        }
    function insertDB(){
            $data['query']= $this->contacts_model->insertlist();
            if($data['query']){
                redirect('contacts/index');
                    
                }
    
            
        }
    }

?&gt;

Views: Contacts_view: it is used for inserting and popping the data in the table
Code:
&lt;body&gt;
        
        <p align=center>&lt;?=$title ?&gt;</p>
        <hr align= "center" width="650px">
        

    &lt;?php
        
        if($insert==1){
            echo '<div align=center>';
            echo form_open('contacts/insertDB');
            echo  ' Name:'.form_input('name');
            echo  'Phone:'.form_input('phone');
            echo  'Email:'.form_input('email');
            echo  '&lt;input type= submit value=Save &gt;';
            echo  form_close();
            echo '<div>';
            }    
        else{
                
        ?&gt;
        &lt;?php
    ?&gt;
    <p align="center">
&lt;?php
             echo anchor('contacts/popInsertWindow','New ');

        ?&gt;
        <table border=0 align="center" width="650px">
        
        <tr bgcolor="#e3e3e3">
        <td></td>
        <td>ID</td>
        <td>Full Name</td>
        <td>Phone</td>
        <td>Email</td>
        </tr>
        &lt;?php
        echo form_open('contacts/popEditWindow');
        
        foreach ($query->result() as $row){
        echo '<tr><td>'.form_checkbox('edit[]',$row->id);
        echo '<td>'.$row->id.'</td><td>'.$row->name.'</td><td>'.$row->phone.
        '</td><td>'.$row->email.'</td></tr>';
        
            }
        
                
        ?&gt;
            <tr>
        <td></td>
        <td>
        </td>
        <td>
        &lt;?php
             echo form_submit('editbutton','Edit');
             echo form_close();

        ?&gt;
        </td>
        <td></td>
        <td></td></td>
        </tr>
    
        </table>
        &lt;?php
        }
        ?&gt;
Model: contacts_model

Code:
class contacts_model extends Model{
    function contacts_model(){
        parent::Model();
    }
    function poplist(){
        $this->db->orderby('id','DESC');
        $query=$this->db->get('contacts');
        return $query;
        }
    function insertlist(){
        $query = $this->db->insert('contacts',$_POST);
        return $query;
        }
        
    function compareID($id){
        $query = $this->db->get_where('contacts', array('id' => $id));
        return $query;
        }
}

the probleM:

how can i populate the data from the table and fill it in the form.
and how to update the table based from the specified ID number from that form
when the update button is submitted
help me.pls.


Messages In This Thread
Update multiple rows in a table - by El Forum - 08-19-2008, 01:41 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 01:45 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 01:56 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 02:52 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 03:21 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 04:07 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 04:32 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 05:14 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 07:31 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 07:04 PM



Theme © iAndrew 2016 - Forum software by © MyBB