Clicking on a text displaying that text in url but unable to show that text in view file.
View:
<div class="applynow"><a href="<?php echo base_url();?>career/apply/<?php echo $r->job_name;?>" class="applyforjob">Apply Now</a></div>
Clicking on the apply now button displaying the job name in URL. But The job name is not dislaying in view file.
Controller:career/apply
function apply()
{
$this->load->model('career_model');
$data['records2']= $this->career_model->getcareerdatas($this->uri->segment(3));
$data['mainpage']='apply';
$this->load->view('templates/template',$data);
}
Career Model:
function getcareerdatas($id)
{
$this->db->select('jobs_list.*');
$this->db->from('jobs_list');
$this->db->where(array('jobs_list.job_name'=>$id));
$q=$this->db->get();
if($q->num_rows()>0)
{
return $q->result();
}
else
{
return false;
}
}
View:
<form name="applynow" id="applynow" enctype="multipart/form-data" method="post" action="<?php echo base_url();?>apply/applynow">
<div class ="applyus">
<?php if(isset($records2) && is_array($records2)):?>
<?php foreach ($records2 as $r):?>
<span class="digit"><?php echo $r->job_name ;?></span>
<?php endforeach;endif;?>
<div class="applyfullname contactname">
<label for="fullname"><font color="black">Full Name</font><span class="mandatory"><font color ="red">*</font></span></label>
<input type="text" class="form-control names" name="fullname" id="fullname " value="<?php echo set_value('fullname');?>" placeholder="Full Name">
<?php echo form_error('fullname', '<div class="error">', '</div>'); ?>
</div>
<div class="applynowemail contactemail">
<label for="email"><font color="black">Email</font><span class="mandatory"><font color ="red">*</font></span></label>
<input type="email" class="form-control emails" id="email" name="email" value="<?php echo set_value('email');?>" placeholder="Email" >
<?php echo form_error('email', '<div class="error">', '</div>'); ?>
</div>
Clicking on apply now button it will open another page in that page it is not displaying the job name.
MYSQL:
+---------+--------------------+--------------------+-----------------+
| jobs_id | job_name | jobs_name | job_description |
+---------+--------------------+--------------------+-----------------+
| 1 | Junior QA Enginner | Junior_QA_Enginner | Description |
| 2 | Junior Engineer | Junior_Enginner | Description |
+---------+--------------------+--------------------+-----------------+
First view is like (take job_id
instead job_name
in url) :
<div class="applynow"><a href="<?php echo base_url();?>career/apply/<?php echo $r->jobs_id;?>" class="applyforjob">Apply Now</a></div>
Now, after clicking on this your controller be like (no need of segment, you can take value of querystring as parameter of function in codeigniter) :
function apply($job_id)
{
$this->load->model('career_model');
$data['records2']= $this->career_model->getcareerdatas($job_id);
$data['mainpage']='apply';
$this->load->view('templates/template',$data);
}
Then your model is (change your query to compare with job_id
instead job_name
) :
function getcareerdatas($id)
{
$this->db->select('jobs_list.*');
$this->db->from('jobs_list');
$this->db->where('jobs_list.jobs_id', $id);
$q = $this->db->get();
return $q->result();
}
Keep the view as it is. If you get matching record with your $jobs_id
then you definitely get data in $records2
.
Try this solution.
Try this
http://www.codeigniter.com/user_guide/database/results.html
function getcareerdatas($id)
{
$this->db->where('job_name', $id);
$q = $this->db->get('jobs_list');
if($q->num_rows() > 0) {
return $q->result();
} else {
return array();
}
}
Make sure your controller has first letter upper case only.
On controller echo $this->uri->segment(3) make sure you are getting correct
Update
Remove && is_array($records2)
just for testing.
<?php if(isset($records2)) {?>
// Other data
<?php }?>