Why is my data not displaying on form? below is the MVC.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • viana2020
    New Member
    • Aug 2015
    • 14

    #1

    Why is my data not displaying on form? below is the MVC.

    my update and delete also giving errors.someone help to figure out where am wrong.


    **controller**

    Code:
    <?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    
    class Attendance extends CI_Controller {
    public function index()
            {
       
                    if($this->input->post('cancel')){
                    $this->newform();
                    }
                    elseif($this->input->post('delete')){
                    $this->load->model('Attendance_model');
                    $data['getData'] = $this->Attendance_model->getdb();
                    $this->Attendance_model->deletedb($this->input->post('delete'));
                    $this->getform($this->input->post('DeptCode'));
                    }
                    elseif($this->input->post('update')){
                    $this->load->model('Attendance_model');
                            if($this->input->post('AttnID')){
                            $this->Attendance_model->updatedb(
                                   $this->input->post('AttnID'),
                                   $this->input->post('EmpNo'),
                                   $this->input->post('EmpName'),
                                   $this->input->post('Designation'),
                                   $this->input->post('DayInTime'),
                                   $this->input->post('EatingOutTime'),
                                   $this->input->post('EatingInTime'),
                                   $this->input->post('DayOutTime'),
                                   $this->input->post('InOutHrs'),
                                   $this->input->post('TotalHrs'),
                                   $this->input->post('NPCode'));
                            }
                            $this->Attendance_model->adddb(
                                            $this->input->post('PostDate'),
                                            $this->input->post('DeptCode'),
                                            $this->input->post('LocCode'),
                                            $this->input->post('LocName'),
                                            $this->input->post('Shift'),
                                            $this->input->post('AddEmpNo'),
                                            $this->input->post('AddEmpName'),
                                            $this->input->post('AddDesignation'),
                                            $this->input->post('AddDayInTime'),
                                            $this->input->post('AddEatingOutTime'),
                                            $this->input->post('AddEatingInTime'),
                                            $this->input->post('AddDayOutTime'),
                                            $this->input->post('AddInOutHrs'),
                                            $this->input->post('AddTotalHrs'),
                                            $this->input->post('AddNPCode'));
                            $this->getform($this->input->post('DeptCode'));
                            }
                    elseif($this->input->post('LocName')){
                    $this->getform($this->input->post('LocName'));
                    }
                    else{
                    $this->newform();
                    }
            }
    
            function newform()
            {
    																$this->load->model('Attendance_model');
                    $this->load->view('header');
                    $this->load->view('topnav');
                    $data['getlocation'] = $this->Attendance_model->getlocation();
    	    											$data['getdeptcode'] = $this->Attendance_model->getdeptcode();
    																$this->load->view('Attendance_form',$data);
    																$this->load->view('footer');
            }
    
    	function getform($DeptCode)
            {
                    $this->load->model('Attendance_model');
                    $this->load->view('header');
                    $this->load->view('topnav');
                    $data['getData'] = $this->Attendance_model->getdb($DeptCode);
                    $this->load->view('Attendance_form',$data);
                    $this->load->view('footer');
            }
      
     
    }
    
    
    
    
    **Model**
    
    
    <?php
    class Attendance_model extends CI_Model {
    
    	function __construct() {
    		parent::__construct();
    	}
    function getdb($DeptCode) {
    	$query = $this->db->query('select AttnMaster.*, AttnDetails.* 
    			from AttnMaster inner join AttnDetails on AttnMaster.ID=AttnDetails.AttnID
    			where AttnMaster.DeptCode = ' .$DeptCode);
    			if($query->result_array()){
    			return $query->result_array();
    		}
    		else
    		{
    		$query = $this->db->query('select *
                            from AttnMaster
                            where ID = ' .$ID);
            	return $query->result_array();
    		}
    	}
    
    	function getlocation(){
    	$query = $this->db->query('select * from LocationMaster');
                    return $query->result_array();
    	} 
    
    	function getdeptcode(){ 
            $query = $this->db->query('select * from LocationDept');
                    return $query->result_array();
            }
            
            
    	
    
    
    	function updatedb($PostDate,$DeptCode,$LocCode,$LocName,$Shift,$AttnID,$EmpNo,$EmpName,$Designation,$DayIntime,$EatingOutTime,$EatingInTime,$DayOutTime,$InOutHrs,$TotalHrs,$NPCode) {
    		foreach($ID as $key=>$row) {
    		$array = array('ID'=>$row,
    		'PostDate'=>$PostDate[$key],
    		'DeptCode'=>$DeptCode[$key],
    		'LocName'=>$LocCode[$key],
    		'Shift'=>$Shift[$key],
    			'EmpNo'=>$EmpNo[$key],
    			'EmpName'=>$EmpName[$key],
    			'Designation'=>$Designation[$key],
    			'DayIntime'=>$DayIntime[$key],
    			'EatingOutTime'=>$EatingOutTime[$key],
    			'EatingInTime'=>$EatingInTime[$key],
    			'DayOutTime'=>$DayOutTime[$key],
    			'inOutHrs'=>$DayIntime[$key],
    			'TotalHrs'=>$TotalHrs[$key],
    			'NPCode'=>$NPCode[$key],
    			);
    		$this->db->where('AttnID', $key);
    		$this->db->update('AttnDetails', $array);
    		}
    	}
    
    	function adddb($PostDate,$DeptCode,$LocCode,$LocName,$Shift,$AttnID,$EmpNo,$EmpName,$Designation,$DayIntime,$EatingOutTime,$EatingInTime,$DayOutTime,$InOutHrs,$TotalHrs,$NpCode) {
    		for($i=1;$i<=5;$i++) {
    			if($AttnID[$i] != 0) {
    			$data = array(
    			'PostDate' => $PostDate[$i],
    			'DeptCode' => $DeptCode[$i],
    			'LocName' => $LocCode[$i],
    			'Shift' => $Shift[$i],
    			'AttnID' => $AttnID[$i],
    			'EmpNo' => $EmpNo[$i],
    			'EmpName' => $EmpName[$i],
    			'Designation' => $Designation[$i],
    			'DayIntime' => $DayIntime[$i],
    			'EatingOutTime' => $EatingOutTime[$i],
    			'EatingInTime' => $EatingInTime[$i],
    			'DayOutTime' => $DayOutTime[$i],
    			'InOutHrs' => $InOutHrs[$i],
    			'TotalHrs' => $TotalHrs[$i],
    			'NPCode' => $NPCode[$i]
    			);
    			$this->db->insert('AttnDetails', $data);
    			}
    		}
    	}
    
    
            function deletedb($deleteId) {
                    foreach($deleteId as $key=>$row) {
    		$this->db->delete('AttnDetails', array('AttnID' => $key));
                    }
            }
    
    
    
    }
    ?>
    
    
    
    **View**
    
    
    <?php
    echo '<h1 class="text-center">Attendance Update</h1>';
    echo '<div class="container"style="width:700px">';
    echo '<table class="table table-striped table-bordered table-hover table-minimal"> <tr class="info"> <th class="text-center">PostDate</th><th class="text-center">Location Name</th><th class="text-center">DepartmentName</th><th class="text-center">Shift</th><th class="text-center"></tr>';
    
    
    $form = array(
            'name'		=> 'Attendance' ,
    									'id'		=> 'attendance',
    );
    $optshift =array(
    												'A' => 'Shift-A',
    												'B' => 'Shift-B');
    $PostDate = array(
            'name'          => 'PostDate',
            'value'         => (isset($getData[0])?$getData[0]['PostDate']:''),
            'maxlength'     => '5',
            'size'          => 'date',
            'class'									=> 'datepicker'
    );
    $LocCode = array(
            'name'          => 'LocName',
    );
    
    $DeptName = array(
            'name'          => 'DeptName',
    );
    $Shift = array(
            'name'          => 'Shift',
            'value'         => '',
            'maxlength'     => '5',
            'size'          => '5',
           
    );
    if(isset($getlocation)){
    foreach($getlocation as $values)
    {
    $LocName[$values['LocCode']] = $values['LocName'];
    } 
    }
    if(isset($getdeptcode)){
    foreach($getdeptcode as $values)
    {
    $DeptName[$values['DeptCode']] = $values['DeptName'];
    } 
    }
    echo form_open('attendance',$form);
    echo "<tr><td>";
    echo form_input($PostDate);
    echo "</td><td>";
    echo form_dropdown($LocCode,$LocName);
    echo "</td><td>";
    echo form_dropdown($DeptName,$DeptName);
    echo "</td><td>";
    echo form_dropdown('Shift',$optshift);
    echo "</td></tr>";
    echo "</table>";
    echo '<table class="table table-striped table-bordered table-hover table-minimal"> 
    <tr class="info"> <th class="text-center">EmpNo</th><th class="text-center">EmpName</th><th class="text-center">Designation</th><th class="text-center">DayIntime</th><th class="text-center">EatingOuttime</th><th class="text-center">EatingIntime</th><th class="text-center">DayOutTime</th><th class="text-center">InOutHrs</th><th class="text-center">TotalHrs</th><th class="text-center">NpCode</th><th class="text-center">Delete?</th></tr>';
    
    if(isset($getData[0]['AttnID'])){
    foreach($getData as $getDataValues)
    {
    $EmpNo = array(
            'name'          => 'EmpNo['.$getDataValues['AttnID'].']',
            'value'         =>	 $getDataValues['EmpNo'],
    							'id'            => 'attndetails',
    
    );
    $EmpName = array(
            'name'          => 'EmpName['.$getDataValues['AttnID'].']',
            'value'         => $getDataValues['EmpName'],
            'maxlength'     => '40',
            'size'          => '40',
            'id'            => 'attndetails',
    );
    
    $Designation = array(
            'name'          => 'DayIntime['.$getDataValues['AttnID'].']',
            'value'         => $getDataValues['Designation'],
            'maxlength'     => '10',
            'size'          => '10',
    
    );
    $DayIntime = array(
            'name'          => 'DayIntime['.$getDataValues['AttnID'].']',
            'value'         => $getDataValues['DayIntime'],
            'maxlength'     => '3',
            'size'          => '3',
           
    	'id'		=> 'DayIntime'.$getDataValues['AttnID'],
    );
    $EatingOuttime = array(
            'name'          => 'EatingOuttime['.$getDataValues['AttnID'].']',
            'value'         => $getDataValues['EatingOuttime'],
            'maxlength'     => '10',
            'size'          => '10',
           
    	'id'		=> 'EatingOuttime'.$getDataValues['AttnID'],
    );
    $EatingIntime = array(
            'name'          => 'EatingIntime['.$getDataValues['AttnID'].']',
            'value'         => $getDataValues['EatingIntime'],
            'maxlength'     => '10',
            'size'          => '10',
           
    	'id'		=> 'EatingIntime'.$getDataValues['AttnID'],
    );
    $DayOuttime = array(
            'name'          => 'DayOuttime['.$getDataValues['AttnID'].']',
            'value'         => $getDataValues['DayOuttime'],
            'maxlength'     => '5',
            'size'          => '5',
           
    	'id'		=> 'DayOuttime'.$getDataValues['AttnID'],
    );
    
    $InOutHrs = array(
            'name'          => 'InOutHrs['.$getDataValues['AttnID'].']',
            'value'         => $getDataValues['InOutHrs'],
            'maxlength'     => '5',
            'size'          => '5',
           
    	'id'		=> 'InOutHrs'.$getDataValues['AttnID'],
    );
    $TotalHrs = array(
            'name'          => 'TotalHrs['.$getDataValues['TotalHrs'].']',
            'value'         => $getDataValues['TotalHrs'],
            'maxlength'     => '5',
            'size'          => '5',
          
    	'id'		=> 'TotalHrs'.$getDataValues['AttnID'],
    );
    $NPCode = array(
            'name'          => 'NPCode['.$getDataValues['AttnID'].']',
            'value'         => '',
    );
    $deleteArray = array(
            'name'          => 'delete['.$getDataValues['AttnID'].']',
            'content'       => '<span class="glyphicon glyphicon-trash"></span>',
            'class'         => 'btn btn-warning btn-delete',
            'type'          => 'submit'
    );
    
    echo "<tr><td>";
    echo form_input($EmpNo);
    echo "</td><td>";
    echo form_input($EmpName);
    echo "</td><td>";
    echo form_input($Designation);
    echo "</td><td>";
    echo form_input($DayIntime);
    echo "</td><td>";
    echo form_input($EatingOuttime);
    echo "</td><td>";
    echo form_input($EatingIntime);
    echo "</td><td>";
    echo form_input($DayOuttime);
    echo "</td><td>";
    echo form_input($InOutHrs);
    echo "</td><td>";
    echo form_input($TotalHrs);
    echo "</td><td>";
    echo form_input($NPCode);
    //echo "</td><td>";
    //echo form_button($deleteArray);
    echo "</td></tr>";
    }
    }
    for($i=1;$i<=10;$i++)
    {
    $EmpNo = array(
            'name'          => 'AddEmpNo['.$i.']',
            'value'         => '' ,
    		'id'		=> 'EmpNo'. $i,
    );
    $EmpName = array(
            'name'          => 'AddEmpName['.$i.']',
            'value'         => '',
            'maxlength'     => '30',
            'size'          => '30',
    	
    	'id'		=> 'EmpName'.$i,
    );
    $Designation = array(
            'name'          => 'AddDesignation['.$i.']',
            'value'         => '',
            'maxlength'     => '30',
            'size'          => '30',
    	
    	'id'		=> 'Designation'.$i,
    
    );
    $DayInTime = array(
            'name'          => 'AddDayIntime['.$i.']',
            'value'         => '',
            'maxlength'     => '',
            'size'          => 'time',
    	
    	'id'		=> 'DayIntime'.$i,
    
    );
    $EatingOutTime = array(
            'name'          => 'AddEatingOutTime['.$i.']',
            'value'         => '',
            'maxlength'     => '',
            'size'          => 'time',
    	
    	'id'		=> 'EatingOutTime'.$i,
    
    );
    $EatingInTime = array(
            'name'          => 'AddEatingInTime['.$i.']',
            'value'         => '',
            'maxlength'     => '',
            'size'          => 'time',
    	
    	'id'		=> 'EatingInTime'.$i,
    
    );
    $DayOutTime = array(
            'name'          => 'AddDayIntime['.$i.']',
            'value'         => '',
            'maxlength'     => '',
            'size'          => 'time',
    
    	'id'		=> 'DayIntime'.$i,
    
    );
    $InOutHrs = array(
            'name'          => 'AddInOutHrs['.$i.']',
            'value'         => '',
            'maxlength'     => '5',
            'size'          => 'time',
    	
    	'id'		=> 'InOutHrs'.$i,
    
    );
    $TotalHrs = array(
            'name'          => 'AddTotalHrs['.$i.']',
            'value'         => '',
            'maxlength'     => '5',
            'size'          => 'time',
    	
    	'id'		=> 'TotalHrs'.$i,
    
    );
    
    $NPCode = array(
            'name'          => 'AddNPCode['.$i.']',
            'value'         => '',
    );
    
    echo "<tr><td>";
    echo form_input($EmpNo);
    echo "</td><td>";
    echo form_input($EmpName);
    echo "</td><td>";
    echo form_input($Designation);
    echo "</td><td>";
    echo form_input($DayInTime);
    echo "</td><td>";
    echo form_input($EatingOutTime);
    echo "</td><td>";
    echo form_input($EatingInTime);
    echo "</td><td>";
    echo form_input($DayOutTime);
    echo "</td><td>";
    echo form_input($InOutHrs);
    echo "</td><td>";
    echo form_input($TotalHrs);
    echo "</td><td>";
    echo form_input($NPCode);
    //echo "</td><td>";
    //echo form_button($deleteArray);
    echo "</td></tr>";
    }
    
    
    echo '<tr class="success"><td  colspan="5">';
    echo form_submit('update', 'Update', 'class="btn btn-success"');
    echo '&nbsp;&nbsp;&nbsp;';
    echo form_submit('cancel', 'Cancel',  'class="btn btn-danger"');
    echo "</td></tr>";
    echo "</table></div>";
    echo form_close();
    
    
    
    ?>
    Last edited by Rabbit; Oct 27 '15, 03:52 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
Working...