开发者

how to echo the database contents in codeigniter while editing

How do i get the form field contents while editing (updating) entries in database ?

my controler is

//edit sidebar contents
function edit_lsidebar(){

        if(isset($_POST['heading'])){
        //adding text fields
        $heading = $this->input->post('heading');
        $content_text = $this->input->post('content_text');
        $url = $this->input->post('url');
        $link_text = $this->input->post('link_text');

        $this->Lside_bar_model->edit_lsidebar($heading, $content_text, $url, $link_text);

        redirect('welcome');
    }
    else $this->load->view('edit_lside_bar', $data);    
}

my model is

function edit_lsidebar($heading, $content_text, $url, $link_text){      
    $data = array(
    'heading'=>$heading,
    'content_text'=>$content_text,
    'url'=> $url,
    'link_text' => $link_text
    );

    $this->db->where('id',$this->uri->segment(3));
   开发者_JAVA百科 $this->db->update('lsidebar', $data);

}

please help


When loading your edit_lside_bar view pass the existing $heading, $content_text, $url, $link_text variables with the data array you're passing to the view.

Then inside the view echo those values as a value attribute for input fields. For example:

Inside your controller:

else {

$data["lside_bar"] = $this->Lside_bar_model->get_lside_bar($id); 
$this->load->view('edit_lside_bar', $data); 

}

Inside your view:

<input type="text" name="heading" value="<?php echo $lside_bar->heading; ?>" />
<textarea name="content_text"><?php echo $lside_bar->content_text; ?></textarea>
....

That should give you a nice push in the right direction. Hope that helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜