Data Fetch and Update with codginater

controller


 public function update() { $user_id = $this->uri->segment(2); $result = $this->customer_model->get_single_user_detail($user_id); $data['page_keywords'] = ''; $data['page_description'] = ''; $data['page_slug'] = 'not-found'; $data['page_title'] = 'Not Found'; if ($this->input->server('REQUEST_METHOD') === 'POST') { $data['formdata'] = $this->customer_model->fetch_data(); //form validation $this->form_validation->set_rules('name', 'name', 'required'); $this->form_validation->set_rules('name', 'name', 'required'); $this->form_validation->set_rules('phonenub', 'Mobile', 'required|min_length[10]|max_length[10]'); $this->form_validation->set_rules('email', 'email', 'required|valid_email'); $this->form_validation->set_rules('password', 'password', 'trim|required|min_length[6]|max_length[32]'); $this->form_validation->set_rules('website', 'website', 'required'); $this->form_validation->set_rules('message', 'message', 'required'); $this->form_validation->set_error_delimiters('<div class="alert alert-danger"><a class="close" data-dismiss="alert">×</a><strong>', '</strong></div>'); if($this->form_validation->run()===TRUE){ $data_to_store = array( 'name' => $this->input->post('name'), 'phonenub' => $this->input->post('phonenub'), 'email' => $this->input->post('email'), 'password' => $this->input->post('password'), 'website' => $this->input->post('website'), 'message' => $this->input->post('message') ); $this->customer_model->update($user_id, $data_to_store); redirect('update/'.$user_id); } // $data['category_list'] = $this->customer_model->get_category_list(); } $data['main_content'] = 'update'; $data['user_detail'] = $result; $this->load->view('includes/front/front_template', $data); }

views


<html>

<style>

table, th, td {

    border: 2px solid black;

background-color:;

color:black;

font-size:15px;

font-weight:500;

font-style:italic;

margin-left:40px;

margin-top:20px;

padding:6px

}

</style>

<body>

<?php

echo

"<table><tr><th>id</th><th>Name</th><th>Email</th><th>Password</th><th>Website</th><th>Message</th><th>Image path</th><th>Update</th><th>Delete</th></tr>";

foreach ($formdata as $value) { 

  echo '<tr>

<td>'.$value['id'].'</td>

<td>'.$value['name'].'</td>

<td>'.$value['email'].'</td>

<td>'.$value['password'].'</td>

<td>'.$value['website'].'</td>

<td>'.$value['message'].'</td>

<td>'.$value['image_path'].'</td>

<td><a href="'.base_url().'index.php/update/'.$value['id'].'">Edit</a></td>

<td><a href="'.base_url().'index.php/Delete/'.$value['id'].'">delete</a></td>


</tr>';

}

?>

</table>

</body>

</html>

model=====

 fetch_data

public function fetch_data(){

$this->db->select('*');

$this->db->from('form');

$query = $this->db->get();

return $query->result_array();

}


update====

function update($id, $data) { $this->db->where('id', $id); $this->db->update('form', $data); $error = $this->db->error(); if(empty($error['message'])) { return true; } else { return false; } }

Comments

Popular posts from this blog

condition in table data for html

my notepad code notes

React.js Notes