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>
<th>Action</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>
<td><a href="jobseekers.php?view=jobseeker-edit&id=<?php
echo $jobseeker['id']?>">Update</a></td>
</tr>
<?php }?>
</table>
</html>
2. In
jobseeker_edit_view.php, type the following:
<html>
<head>
<title>Jobseeker Edit | BizjobFinder</title>
<link href='/bizjobfinder.com/css/style.css'
rel='stylesheet'
type='text/css'></link>
</head>
<body>
<div><h4>Editing</h4></div>
<hr>
<div>
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/bizjobfinder.com/application/models/jobseeker_model.php';
$obj=new jobseeker_model();
$jobseeker=$obj->get_jobseeker($_GET['id']);
?>
<form method="post"
action="jobseekers.php?model=jobseeker-update">
<input type="hidden"
name="id"
value="<?php
echo $_GET['id']?>"/>
<div class='form-row'>
<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'> </span>
<input type='submit' name='submit' value='Done'/>
</div>
</form>
</body>
</html>
3. In
jobseekers.php, type the following:
<?php
session_start();
/*
*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';
}
public function edit(){
return 'views/jobseeker_edit_view';
}
public function update(){ require_once($_SERVER['DOCUMENT_ROOT'].'/bizjobfinder.com/application/models/jobseeker_model.php');
$jobseeker = new jobseeker_model();
$jobseeker->id=$_POST['id'];
$jobseeker->firstname
= $_POST['firstname'];
$jobseeker->mi
= $_POST['mi'];
$jobseeker->lastname
= $_POST['lastname'];
$jobseeker->street_barangay
= $_POST['street_barangay'];
$jobseeker->town_city
= $_POST['town_city'];
$jobseeker->province
= $_POST['province'];
return $jobseeker->update($jobseeker);
}
}
$obj = new
jobseekers();
$view = '';
$model = '';
if(!empty($_GET['view'])){
$view = $_GET['view'];
switch($view){
case 'jobseeker-list':
$page=$obj->jobseeker_list();
break;
case 'jobseeker-edit':
$page=$obj->edit();
break;
}
include $_SERVER['DOCUMENT_ROOT'].'/bizjobfinder.com/application/'.$page.'.php';
}
else{
if(!empty($_GET['model'])){
$model
= $_GET['model'];
switch($model){
case 'jobseeker-update':
$result=$obj->update();
header('Location:jobseekers.php?view=jobseeker-list');
break;
}
}
}
/*
*End of file jobseekers.php
*Location:/application/controllers/jobseekers.php
*/
?>
4. 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 $id;
public $firstname;
public $mi;
public $lastname;
public $street_barangay;
public $town_city;
public $province;
public function __construct(){}
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;
}
public function get_jobseeker($id){
$sql="SELECT * FROM jobseekers WHERE id=$id";
$db=$this->_open_connection();
$result=mysql_query($sql,$db);
if($this->_confirm_query($result)){
$row=mysql_fetch_array($result);
$jobseeker=array('firstname'=>$row['firstname'],'lastname'=>$ ['lastname'],
'mi'=>$row['mi'],'street_barangay'=>$row['street_barangay'], 'town_city'=>$row['town_city'],
'province'=>$row['province']);
return $jobseeker;
}
}
public function
update($jobseeker){
$sql="UPDATE jobseekers SET firstname='{$jobseeker->firstname}',
mi='{$jobseeker->mi}',lastname='{$jobseeker->lastname}',
street_barangay='{$jobseeker->street_barangay}',
town_city='{$jobseeker->town_city}',
province='{$jobseeker->province}'
WHERE
id='{$jobseeker->id}'";
$db=$this->_open_connection();
$result=mysql_query($sql,$db);
return $this->_confirm_query($result);
}
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;
}
}
?>
5. 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>
6. On
your browser, type the following:
http://localhost/bizjobfinder.com/
No comments:
Post a Comment