Chici Fitriyanti Angraeni Abdulfattah


Agustus 06, 2012

Practice 5 Code Igniter Update and pagination


Next Practice , its make Update form and add pagination in you're project code igniter..

i will tell you with english, because i wanna try my english its make a people can understand what i mean or not...
please send me a email when i have something wrong with my description...

lest rock with code igniter .. ^^

if you're do my last practice its about insert data, you can easy for make a update data...
but in update data you're just add a one function for get the data..
type source code below :


the source code using at modelNews,

"public function select()
{
$this->db->select('title, content');
$q = $this->db->get('news');
$data = array();
if($q->num_rows() > 0) {
foreach($q->result_array() as $row) {
$data[] = $row;
}
}
return $data;
}

// to update recor
function update($t,$c,$id)
{
$data = array(
'title' => $t,
'content' => $c
);
$this->db->where('id', $id);
$this->db->update('news', $data);
}


and for call the view, you make a new file "view_update.php" save at view folde you can copy the view_input source code because its same.





My Form and in you're controller add a function update for call the model
type the code below ;

"public function update ($id="")
{

$this->load->library('form_validation');
$this->form_validation->set_rules('Title', 'Title', 'required |trim');
$this->form_validation->set_rules('Content', 'Content', 'required | trim');
if ($this->form_validation->run() == FALSE)
{
$data['id']=$id;
$this->load->view('news/view_update',$data);
}
else
{
$id=$this->input->post('id');
$t=$this->input->post('Title');
$c=$this->input->post('Content');
//echo $id;
//exit;
$this->ModelNews->update($t,$c,$id);
//$this->load->view('news/formsucces');
echo "Berhasil";
redirect ('news/show');
}
}" (please delete "")


when you're type the code.. try in web browser.. for test its works or not..
for execution http ://localhost/d4b6/news/input



you must type the title and content, after that submit and the page will be show the data
be like this :




klik Update and type again what you want to change. example :
you want to change title: "Adinda Fitri Rahayu" and content : "Seamolec"



look at the Id its the same ID but the title and content has been change.
yey congratulation you can change the list news.



--------------------------------------------------------------------------------------------------------------------

and for the pagination you just copy the pagination source code at user guide in code igniter and paste to the one function in controller.


example :





you just change the base url and for the ouput i will show to you below :




ok guys may be just it i want to sharing, if i have a next pratice i will be posting in my blog...




Best Regards,


Chici














































0 comments:

Posting Komentar