6.Editing/Updating data on the database


Easy Steps:

1.     On your notepad++, edit jobseeker_list_view.php in C:\xampp\htdocs\application\views with the following code:
<html>
<head>
<title>Jobseekers | BizjobFinder</title>
<link href='<?php echo base_url()?>css/style.css' rel='stylesheet' type='text/css'></link>
</head>
<body>
<?php if(!empty($jobseekers)){?>
<div>Total Jobseekers: <?php echo count($jobseekers); ?></div>
   <div>
      <table id="tbl">
                  <tr>
                              <th>ID</th>
                              <th>Name</th>
                              <th>Address</th>
                              <th>Action</th>
                  </tr>
                  <?php
                              foreach($jobseekers as $jobseeker) { ?>
                                          <tr class="row">
                                                      <td><?php echo $jobseeker['id']?></td>
                                                      <td><?php echo $jobseeker['lastname'].'               
                                                                                          '.$jobseeker['firstname'].'
                                                                                          '.$jobseeker['mi']?></td>
                                                      <td><?php echo $jobseeker['street_barangay'].'
                                                                                            '.$jobseeker['town_city'].'
                                                                                            '.$jobseeker['province']?></td>
                                              <td>
                                                   <a href="<?php echo base_url()?>jobseeker-edit-<?php echo
                                                            $jobseeker['id']?>">Edit</a>
                                               </td>
                                          </tr>
                  <?php } ?>
      </table>
   </div>
   <?php } else { ?>
   <div>
                  <?php echo $msg; ?>
   </div>
   <?php }?>
</body>
</html>

2.     Edit routes.php located on: C:\xampp\htdocs\application\config by adding the following code:
$route['jobseeker-edit-(:num)'] = "jobseekers/edit/$1";

3.     Edit jobseekers.php located on: C:\xampp\htdocs\application\controllers by adding the following code:
function edit($id){
                  $result=$this->jobseeker->edit($id);
                  if($result){
                              $data['jobseeker']=$result;
                              $this->load->view('jobseeker_edit_view',$data);
                  }
 }

4.     Edit jobseeker_model.php located on: C:\xampp\htdocs\application\models by adding the following code:
function edit($id){
                        $this->db->where('id',$id);
                        $result = $this->db->get($this->table);
                        return $result->row_array();
}

5.     Create file named jobseeker_edit_view.php in C:\xampp\htdocs\application\views with the following code:
<html>
<head>
      <title>Jobseeker Signup | BizjobFinder</title>
      <link href='<?php echo base_url()?>css/style.css' rel='stylesheet' type='text/css'></link>
</head>
<body>
<div><h4>Editing Jobseeker</h4></div>
<hr>
      <form method='post' action="<?php echo base_url()?>jobseeker-update">
      <div>
                  <div class='form-row'>
                              <input type='hidden' name='id' value="<?php echo $jobseeker['id']?>"/>
                              <span class='label'>Firstname:</span>
                              <input type='text' name='firstname'
                                                  value="<?php echo  $jobseeker['firstname']?>"/>
                  </div>
                  <div class='form-row'>
                              <span class='label'>MI:</span>
                              <input type='text' name='mi' value="<?php echo $jobseeker['mi']; ?>"/>
                  </div>
                  <div class='form-row'>
                              <span class='label'>Lastname:</span>
                              <input type='text' name='lastname'
                                                 value="<?php echo $jobseeker['lastname']; ?>"/>
                  </div>
                  <div class='form-row'>
                              <span class='label'>Street/Barangay:</span>
                              <input type='text' name='street_barangay'
                                                  value="<?php echo $jobseeker['street_barangay'];?>"/>
                  </div>
                  <div class='form-row'>
                              <span class='label'>Town/City:</span>
                              <input type='text' name='town_city'
                                                  value="<?php echo $jobseeker['town_city'];?>"/>
                  </div>
                  <div class='form-row'>
                              <span class='label'>Province:</span>
                              <input type='text' name='province'
                                                  value="<?php echo $jobseeker['province'];?>"/>
                  </div>
                  <div class='form-row'>
                              <span class='label'>&nbsp;</span>
                              <input type='submit' name='submit' value='Update'/>
                  </div>
      </form>
</body>
</html>

6.     Edit routes.php located on: C:\xampp\htdocs\application\config by adding the following code:
$route['jobseeker-update'] = "jobseekers/update";

7.     Edit jobseekers.php located on: C:\xampp\htdocs\application\controllers by adding the following code:
function update(){
                        $data = $this->input->post();
                        $result = $this->jobseeker->update($data);
                        redirect(base_url().'jobseeker-list');         
}

8.     Edit jobseeker_model.php located on: C:\xampp\htdocs\application\models by adding the following code:
function update($data){
                        $id = $data['id'];
                        unset($data['submit']);
                        $this->db->where('id',$id);
                        $result = $this->db->update($this->table,$data);
                        return $result;
}

9.     Put your code to the test, perfect!, nice jobJ

1 comment: