Welcome Guest, Not a member yet? Register   Sign In
help me with the edit code
#1

[eluser]sanket[/eluser]
hey m a newbie to code igniter i am makin a page in which i can inert edit n delete names i done wid insert and delete but m not abke to perform the edit part can anyon pls help me otta this???

Code:
my controller code

function edit()
    {
        if($this->insmodel->Get($this->uri->segment(3)))
        $this->insmodel->edit($this->uri->segment(3));
    }

model code

function edit($id)
{
    $name = $this->input->post('name');
    $id = $this->uri->segment(3);
    $data = array(
                  'testname' => "sss"
                 );

    $this->db->where('id', $id);
    $this->db->update('test', $data);
    redirect('insertdata');
}

view code

<?php
if(isset($friendlist)){
     foreach($friendlist as $row)
     {
         echo "<br/>".$row['testname']."&nbsp;&nbsp;".
         "("."<a >edit</a>"."&nbsp;/&nbsp;".
         "<a >delete</a>".")"."<br/>";
        
     }
        
}
?&gt;
#2

[eluser]NateL[/eluser]
i think your if statement is off in the model, to begin with:
Code:
if($this->insmodel->get($this->uri->segment(3))){
        $this->insmodel->edit($this->uri->segment(3));
}

uhh your foreach statement in your view code is anything but pretty...woa...

Code:
&lt;?php foreach($friendlist as $row): ?&gt;
     <br />&lt;?=$row['testname']?&gt; &nbsp;&nbsp; (<a href="">edit</a>&nbsp;&nbsp;<a href="">delete</a>)<br />
&lt;?php endforeach; ?&gt;

the beauty of PHP is you can break in and out of HTML. Break out of php, write up your HTML, and it makes it a hellova lot easier to read Smile

That's probably not all of the mistakes there are...just what I was able to find at a quick glance. I didn't test them to work..i just re-wrote them how I would write them Smile

Have you watched the video tutorials?




Theme © iAndrew 2016 - Forum software by © MyBB