I'm creating a website and I've been trying to connect to the database, I really can't find the problem. all I need is to get all "job_desc" from my database "bcjobs" and after a user can click a "job_desc" for him to be able to see the full details of a job. here's my code
Model:
<?php
class Jobs_model extends CI_Model {
public function __construct() {
$this->load->database();
}
public function get_job($slug = FALSE){
if($slug === FALSE){
$query = $this->db->get('employer_postjob');
return $query->result_array();
}
$query = $this->db->get_where('employer_postjob',array('job_desc'=>$slug));
return $query->row_array();
}
}
?>
Controller:
<?php
class Jobs extends CI_Controller {
public function __contruct() {
parent::__construct();
$this->load->model('jobs_model');
}
public function index() {
$data['job'] = $this->jobs_model->get_job();
$data['title'] = 'Job List';
$this->load->view('templates/header', $data);
$this->load->view('templates/navigation', $data);
$this->load->view('joblist/index', $data);
$this->load->view('templates/footer', $data);
}
public function view($slug) {
$data['job_item'] = $this->jobs_model->get_job();
if (empty($data['job_item'])) {
echo "no data";
}
$data['title'] = $data['job_item']['title'];
$this->load->view('templates/header', $data);
$this->load->view('templates/navigation', $data);
$this->load->view('joblist/view', $data);
$this->load->view('templates/footer', $data);
}
}
?>
application/views/joblist/index.php:
<?php foreach ($job as $job_item): ?>
<h2><?php echo $job_item['title'] ?></h2>
<div id="main">
<?php echo $job_item['text'] ?>
</div>
<p><a href="joblist/<?php echo $job_item['slug'] ?>">View article</a></p>
<?php endforeach ?>
application/views/joblist/view.php:
<?php
echo '<h2>'.$job_item['title'].'</h2>';
echo $job_item['text'];
routes:
$route['jobs/(:any)'] = 'joblist/$1';
$route['jobs'] = 'joblist';
$route['(:any)'] = 'pages/$1';
$route['default_controller'] = 'pages';
\n"; exit();` throughout the code to attempt to isolate the problem. – J.D. Pace May 29 '13 at 02:59