6.How to get data from the database?

1.    In jobseeker_list_view.php, type the following:
<html>
<head>
<title>Jobseeker-List | BizjobFinder.com</title>
</head>
<body>
<table border='1'>
<tr>
<th>ID</th>
<th>Lastname</th>
<th>Firstname</th>
<th>MI</th>
<th>Address</th>
</tr>
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/bizjobfinder.com/application/models/jobseeker_model.php';
$obj=new jobseeker_model();
$jobseekers=$obj->get_all_jobseekers();
$ctr=0;
foreach($jobseekers as $jobseeker){?>
<tr>
    <td><?php echo $jobseeker['id'];?></td>
    <td><?php echo $jobseeker['lastname']?></td>
    <td><?php echo $jobseeker['firstname']?></td>
    <td><?php echo $jobseeker['mi']?></td>
    <td><?php echo $jobseeker['street_barangay'].' '.$jobseeker['town_city'].','.$jobseeker['province']?></td>
</tr>
<?php }?>

</table>
</html>

2.    In jobseekers.php, type the following:
<?php
/*
*Filename:jobseekers.php
*projectname:bizjobfinder.com
*Date created:November 18,2011
*Created by:Mario T. Silvano,
*/
?>
<?php
      class jobseekers{
                  public function jobseeker_list(){
                              return 'views/jobseeker_list_view';
                  }
      }

      $obj = new jobseekers();
      $view = '';
      if(!empty($_GET['view'])){
                  $view = $_GET['view'];
                  switch($view){                        
                              case 'jobseeker-list':
                                          $page=$obj->jobseeker_list();
                              break;
                             
                  }
      include $_SERVER['DOCUMENT_ROOT'].'/bizjobfinder.com/application/'.$page.'.php';
      }
/*
*End of file jobseekers.php
*Location:/application/controllers/jobseekers.php
*/
?>

3.    In jobseeker_model.php, type the following:
<?php
define("DB_SERVER","localhost");
define("DB_USER","root");
define("DB_PASS","");
define("DB_NAME","bizjobfinder_db");

class jobseeker_model{
      public function get_all_jobseekers(){
                  $sql="SELECT * FROM jobseekers
                  ORDER BY lastname";
                  $db=$this->_open_connection();
                  $result=mysql_query($sql,$db);
                  $jobseekers=array();
                  if($this->_confirm_query($result)){
                              while($r=mysql_fetch_array($result)){
                                          $row=array();
                                          foreach($r as $k=>$v){
                                                      $row[$k]=$v;
                                          }
                                          array_push($jobseekers,$row);
                                          unset($row);
                              }          
                  }
                  return $jobseekers;
      }
      private function _open_connection(){
                  $con = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
                  if(!$con)die('Error Connection:'.mysql_error());
                  $db_select = mysql_select_db(DB_NAME,$con);
                  if(!$db_select)die('Error Selection:'.mysql_error());
                  return $con;
      }
      private function _confirm_query($result){
                  if(!$result)die('Error Query:'.mysql_error());
                  return $result;
      }
}
?>

4.    In index.php, type the following:
<html>
<head>
      <title>Home | BizjobFinder</title>
      <link href='/bizjobfinder.com/css/style.css' rel='stylesheet' type='text/css'></link>
</head>
<body>
<a href='application/controllers/jobseekers.php?view=jobseeker-list'>Job Seeker List</a><br>
</body>
</html>

5.    On your browser, type the following:
http://localhost/bizjobfinder.com/



4 comments: