Welcome Guest, Not a member yet? Register   Sign In
Load a new view with the next record in the db
#1

[eluser]afro[/eluser]
Am developing a online leave management system and am stuck at this point of load a new view with the next leave for approval after an application has been approved or rejected by approving officer, what I want is that a new similar view should load when the submit button is clicked.

Please help me out.


Thank you.
#2

[eluser]InsiteFX[/eluser]
Just load the new view like you normally do.

InsiteFX
#3

[eluser]afro[/eluser]
@InsiteFX

The new view has to contain the details of the next pending leave so that it can be approved,i have a problem loading the data from the db to the new view
#4

[eluser]InsiteFX[/eluser]
Show your method code where your getting the data from the database.

InsiteFX
#5

[eluser]afro[/eluser]
1.the view
Code:
<div id="leaveapproval">&lt;?php echo $num_results;?&gt; pending leave(s)found</b>
&lt;?php echo form_open('administration/processleave');?&gt;<table border="1" align="center" id="leaveapprovaltable"><tbody>&lt;?php foreach($leaves as $leave):?&gt;<tr><td>Application Id</td><td>&lt;input type="text" name="applicationid" value="&lt;?php echo $leave-&gt;ApplicationId;?&gt;" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Staff Name</td><td>&lt;input type="text" name="staffname" value="&lt;?php echo $leave-&gt;StaffName; ?&gt;" readonly="readonly" onfocus="this.blur();"/></td></tr>
<tr><td>Leave Balance</td><td>&lt;input type="text" name="leavebalance" value="&lt;?php echo $leave-&gt;LeaveBalance; ?&gt;" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Days Requested</td><td>&lt;input type="text" name="noofdaysrequested" value="&lt;?php echo $leave-&gt;NoofDaysRequested; ?&gt;" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Leave Type</td><td>&lt;input type="text" name="leavetype" value="&lt;?php echo $leave-&gt;LeaveType; ?&gt;" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Commencement Date</td><td>&lt;input type="text" name="commencementdate" value="&lt;?php echo $leave-&gt;CommencementDate; ?&gt;" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Reporting Back</td><td>&lt;input type="text" name="Dateforreportingback" value="&lt;?php echo $leave-&gt;Dateforreportingback;?&gt;" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Current Project</td><td>&lt;input type="text" name="currentproject" value="&lt;?php echo $leave-&gt;CurrentProject; ?&gt;" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Handed To</td><td>&lt;input type="text" name="handedto" value="&lt;?php echo $leave-&gt;HandedTo; ?&gt;" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Comment</td><td>&lt;input type="text" name="comment" value="&lt;?php echo $leave-&gt;Comment;?&gt;" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td colspan="2" align="center"> Appove:&lt;?php echo form_radio('approve','Approved');?&gt;Reject: &lt;?php echo form_radio('approve','Rejected');?&gt;</td></tr><tr><td colspan="2" align="center">&lt;?php echo form_submit('leaveapproval','Submit Form'), form_reset('reset','Cancel');?&gt;</td></tr>&lt;?php endforeach; ?&gt;</tbody></table>
2.The controller
Code:
class Administration extends Controller{
function processleave(){
parent::controller();$this->load->helper(array ('url')); $this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div id="prompt_error">', '</div>'); $this->form_validation->set_rules('approve','Approval','required');
if($this->form_validation->run()==FALSE)
{$this->load->view('administration'); else{$this->load->model('Administration_model');
$query = $this->Administration_model->approvedleaves();}
if($query){$offset=0,$limit = 1; $this->load->model('Administration_model');
  $results = $this->Administration_model->search($limit, $offset);$data['leaves'] = $results['rows'];
  $data['num_results'] = $results['num_rows'];$this->load->library('pagination');
  $config = array();$config['base_url'] = site_url("Administration_model/search");
  $config['total_rows'] = $data['num_results'];$config['per_page'] = $limit; $config['uri_segment'] = 5; $this->pagination->initialize($config); $data['pagination'] = $this->pagination->create_links();    
  redirect('administration',$data);}}
public function nextleave()
  {$offset=0,$limit = 1;$results = $this->search($limit, $offset);$data['leaves'] = $results['rows'];
  $data['num_results'] = $results['num_rows'];$this->load->library('pagination'); $config = array(); $config['base_url'] = site_url("Administration_model/search"); $config['total_rows'] = $data['num_results']; $config['per_page'] = $limit; $config['uri_segment'] = 5;$this->pagination->initialize($config); $data['pagination'] = $this->pagination->create_links(); redirect('administration',$data);}}
3. The model class is as follows
Code:
class Administration_model extends Model{
public function search($limit, $offset)
  {parent::Model();
$q = $this->db->select('ApplicationId, StaffName, LeaveBalance, NoofDaysRequested, LeaveType, CommencementDate, Dateforreportingback, CurrentProject, HandedTo, Comment');        
$this->db->from('appliedleaves');
$where = "Status = 'Pending'";
$this->db->where($where);$this->db->limit($limit, $offset);$ret['rows'] = $q->get()->result();
$q= $this->db->select('COUNT(*) as count', FALSE); $where = "Status = 'Pending'"; $this->db->where($where);
$this->db->from('appliedleaves'); $tmp = $q->get()->result(); $ret['num_rows'] = $tmp[0]->count;return $ret;}
function approvedleaves(){
$approve = "Status ='" . mysql_real_escape_string($this->input->post('approve')) . "' WHERE ApplicationId LIKE " . mysql_real_escape_string($this->input->post('applicationid'));
$query = $this->db->update('appliedleaves',$approve);
if($query = 1)
{$approvedleaves=array('ApplicationId'=>$this->input->post('applicationid'),'StaffName'=>$this->input->post('staffname'),'LeaveBalance'=>$this->input->post('leavebalance'),'DaysRequested'=>$this->input->post('noofdaysrequested'),'LeaveType'=>$this->input->post('leavetype'),'CommencementDate'=>$this->input->post('commencedate'),'ReportingBack'=>$this->input->post('dateforreportingdate'),'CurrentProject'=>$this->input->post('currentproject'),'HandedTo'=>$this->input->post('handedto'),'Comment'=>$this->input->post('comment') );
$query = $this->db->insert('helpdesklevel_leaves', $approvedleaves);
if($query){
/*i want after the approved/rejected leave has been saved, i want the system to load the next leave from the db to the  view at this point*/
class Administration::nextleave();}}}}
#6

[eluser]InsiteFX[/eluser]
If your using CodeIgniter 2.0.0 then you need to change Controller to CI_Controller and Model to CI_Model.

And I hope you do not expect us to try and read that code!

Look in the CodeIgniter User Guide database active record!

InsiteFX
#7

[eluser]afro[/eluser]
I got a way that solved that particular problem

Thanks anyway for trying to help


I came up with a helper class that i called at the end of the


controller class and to my surprise it worked, am know almost thru' with

the system.




Theme © iAndrew 2016 - Forum software by © MyBB