5.Displaying data from the database

Easy Steps:

1.     On your notepad++, edit the home_view.php in C:\xampp\htdocs\application\views by adding the following code:
<div>
      <a href="<?php echo base_url()?>jobseeker-list">Jobseeker List</a>
</div>

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

3.     Edit jobseekers.php located on: C:\xampp\htdocs\application\controllers by adding the following code:
function getAll(){
                  $result=$this->jobseeker->get_all();
                  if(!$result){
                              $data['msg']="No  jobseekers yet.";
                              }
                  else{
                              $data['jobseekers']=$result;
                              }          
                  $this->load->view('jobseeker_list_view',$data);
      }

4.     Edit jobseeker_model.php located on: C:\xampp\htdocs\application\models by adding the following code:
function get_all(){
                        $result = $this->db->get($this->table);
                        if( $result->num_rows > 0 ) {
                                    return $result->result_array();
                        }
                        else{
                                    return false;
                        }
            }

5.     Create file named jobseeker_list_view.php in C:\xampp\htdocs\application\views with the following code:
<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>
                  </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>
                                          </tr>
                  <?php } ?>
      </table>
   </div>
   <?php } else { ?>
   <div>
                  <?php echo $msg; ?>
   </div>
   <?php }?>
</body>
</html>

6.     Edit style.css located on: C:\xampp\htdocs\css  by adding the following code:
#tbl th {border-bottom: 1px dashed #CCCCCC;

    font-size: 14px;
    font-weight: bold;
    padding: 12px 17px;
    text-align:left;
      }
#tbl td {

    padding: 7px 17px;
}
#tbl .row:hover {

    background:#E3E4E5;
}
#tbl{
    border: 1px solid #CCCCCC;
    border-collapse: collapse;
    font-size: 12px;
    margin: 0 10px;
    text-align: left;
}

7.     Put your code to the test, click the link the Jobseeker List and you will see somewhat like this:


8.     Congrats!, nice jobJ

No comments:

Post a Comment