Click here to Skip to main content
15,071,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm currently in troubled on how to find a solution for this. So to start with, i am displaying project work details and I just cant find out why it keeps on fetching all data wherein there exceptions on the query. The problem with that was probably i could not pass the ProjectID into the model and thus, it doesn't recognize a unique key and doesn't display details in the specified project. Need help please. Much appreciated. :) BTW i am using code igniter. I am inserting my code below for you to find out! thanks!

===================================================================================
PROJECT VIEW

<?php 
include ('fragments/profile_header.php');
include('fragments/profile_nav.php');
?>

<div class="content-wrapper">
 
  <section class="content">
          <!-- table -->

          <div class="box box-primary" id="projectman">
              <div class="box-header">
                  <h2 class="box-title">Poject Management</h2>   

              <div class="box-tools pull-right">
                  <a href="AddProject"><button type="button" class="btn btn-primary">class="fa fa-plus" id="table2" rowspan="1" colspan="1" style="width: 120px" title="EDIT FRAME"__^ Edit
                      </button>
                      <button class="btn btn-flat btn-warning btn-sm" title="ADD PROJECT WORK" onclick="view('."'".$project->ProjectID."'".')">^__i class="fa fa-plus"__^</i> Add Project Work
                      </button>
                  </td>
                  </tr>';
                  }

                  ?>

          </tbody>
          </table>  
              </div><!-- end box body -->
              </div>

              <div class="box-footer hidden" id="projwork">
              <h3 class="header-title">^__strong> Project: <label name="projectname"></label></h3>
        
                       <input type="hidden" name="proj_id">
        <div class="form-group">
        <!-- table -->
        <div class="col-md-7">
                <div class="box box-primary">
                <div class="box-header with-border">
                  <h3 class="box-title">^__strong> Project Work Details</h3>
                </div>
                <div class="box-body">
                    <table id="table" class="table table-bordered table-striped dataTable" role="grid" aria-describedby="example1_info">
                        <thead>
                        <tr>
                            <th>Project Program Work ID</th>
                            <th>Project Work Description</th>
                            <th>Contract Amount</th>
                           <!--  <th>Action    </th> -->
                        </tr>
                        </thead>
                        <tbody>
                       <?php
                  $pm_project = $this->pmmm->get_project_programwork2();

                  foreach ($pm_project as $pm_project) {
                      echo'<tr>
                      <td style="text-transform: capitalize;font-size:14px">'.$pm_project->Project_ProgramWorkID.'</td>
                  <td style="text-transform: capitalize;font-size:14px">'.$pm_project->ProgramWorkDescription.'</td>
                   <td style="text-transform: capitalize;font-size:14px">'.$pm_project->ContractAmount.'</td>
                  </tr>';
                  }

                  ?>
                        </tbody>
                      </table>
                        
                </div>
                </div>
        </div>
        </div>

             
        <!-- add project work -->
        <div class="col-md-5">
              <div class="box box-primary">
                <div class="box-header with-border">
                  <h3 class="box-title">^__strong> Add Project Work</h3>
                </div>
                <div class="box-body">
                       <?php echo form_open_multipart('ProjectManagement/add_work');?>
                       <div class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">Project Work Description</label>
                            <!-- from databese tbl_programwork -->
                            <div class="col-sm-8">
                                <select type="text" class="form-control" name="ProgramWork" required>
                               <?php
                          $work = $this->pmmm->get_progwork();
                          foreach ($work as $work) {
                             echo '<option value='.$work->ProgramWorkID.'>'.$work->ProgramWorkDescription.'</option>';
                          }
                        ?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label">Contract Amount</label>
                            <div class="col-sm-5">
                                    <input type="number" class="form-control" name="ContractAmount" placeholder="₱ 0, 000, 000" required>
                            </div>
                        </div>
                        </div>

                        <div class="box-footer">
                    <!-- will be save in tbl_project_programwork -->
                       <button type="submit" class="btn btn-primary pull-right">SAVE PROJECT WORK</button> 
                        </div></div>
                       </form>
              </div>
        </div>
    </div>  
            
         </div></div></section> </div><!-- end box -->
  </section>
</div><!-- end content wrapper -->


<?php 
include('fragments/profile_footer.php');
        // include('fragments/profile_scipt.php');
?>

           <!--  EDIT PROJECT MODAL-->

<!-- <div class="modal modal-default" id="edit_form" role="dialog">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
              <h3 class="modal-title">Update Project Details</h3>
            </div>
            <div class="modal-body form">
             <form action="#" id="editForm" class="form-horizontal">
            <input type="hidden" value="" name="employee_id" id="employee_id" /> 
               <div class="form-group">
            <label class="control-label col-md-3">Project No.</label>
            <div class="col-md-9">
              <input name="proj_no"  class="form-control" type="text" >
              <span class="help-block"></span>
            </div>
          </div>
           <div class="form-group">
            <label class="control-label col-md-3">Project Supervisor</label>
            <div class="col-md-9">
             <select type="text" class="form-control" name="proj_sup">
                               <?php
                          $emp = $this->pmmm->get_employee();
                          foreach ($emp as $emp) {
                             echo '<option value='.$emp->WorkerID.'>'.$emp->Name.'</option>';
                          }
                        ?>
                                </select>
            </div>
          </div>
           <div class="form-group">
            <label class="control-label col-md-3">Project Name</label>
            <div class="col-md-9">
              <input name="proj_name"  class="form-control" type="text" >
              <span class="help-block"></span>
            </div>
          </div>
           <div class="form-group">
            <label class="control-label col-md-3">Location</label>
            <div class="col-md-9">
              <input name="loc"  class="form-control" type="text" >
              <span class="help-block"></span>
            </div>
          </div>
           <div class="form-group">
            <label class="control-label col-md-3">Contractor Cost</label>
            <div class="col-md-9">
              <input name="cont_cost"  class="form-control" type="text" >
              <span class="help-block"></span>
            </div>
          </div>
           <div class="form-group">
            <label class="control-label col-md-3">Date Startedr</label>
            <div class="col-md-9">
              <input name="date_start"  class="form-control" type="text" >
              <span class="help-block"></span>
            </div>
          </div>
           <div class="form-group">
            <label class="control-label col-md-3">Contract Period</label>
            <div class="col-md-9">
              <input name="cont_per"  class="form-control" type="text" >
              <span class="help-block"></span>
            </div>
          </div>
           <div class="form-group">
            <label class="control-label col-md-3">Conforme</label>
            <div class="col-md-9">
              <input name="confor"  class="form-control" type="text" >
              <span class="help-block"></span>
            </div>
          </div>
        </form>
            </div>
            <div class="modal-footer"> 
              <button type="button" id="btnUpdate" onclick="save()" class="btn btn-primary">Update</button>
              <button type="button" class="btn btn-danger btn-flat pull-left" data-dismiss="modal">Cancel</button>
            </div>
          </div>
        </div>
      </div>
 -->
<script type="text/javascript">
    $(document).ready(function() {
        $('#table2').DataTable({
          "paging": true,
          "lengthChange": true,
          "searching": true,
          "ordering": true,
          "info": true,
          "autoWidth": false,
          pageLength:10
        });
       }); 
    $(document).ready(function(){
      $('#table').DataTable();
});

    function view(project_id){
     

      $.ajax({
          url: "<?php echo site_url('ProjectManagement/ajax_view_program/')?>" + project_id,
      type: "GET",
      dataType: "JSON",
      success: function(data){
        console.log(data);
        $('[name="projectname"]').text(data[0].ProjectName);
        $('[name="ProgramWork"]').text(data[0].ProgramWorkID);
        $('[name="proj_id"]').val(data[0].ProjectID);
        $('#projwork').removeClass("hidden");
        $('#projectman').addClass("hidden");
   
      },
       error: function(jqXHR, textStatus, errorThrown)
      {
        alert('Error retreiving data');
      }
      });
    }

      //-----EDIT PROJECT FUNCTIONS//

 // function edit_project(ProjectID){
        
 //       $('#editForm')[0].reset();
 //        $.ajax({
 //          url: "<?php echo site_url('ProjectManagement/ajax_view_project/')?>" + ProjectID,
 //          type:"GET",
 //          dataType: "JSON",
 //          success: function(data)
 //          {
 //            console.log(data);
            

 //            $('[name="proj_no"]').val(data[0].ProjectNo);
 //            $('[name="proj_sup"]').val(data[0].WorkerID);
 //            $('[name="proj_name"]').val(data[0].ProjectName);
 //            $('[name="loc"]').val(data[0].Location);
 //            $('[name="cont_cost"]').val(data[0].ContractorCost);
 //            $('[name="date_start"]').val(data[0].DateStarted);
 //            $('[name="cont_per"]').val(data[0].ContractPeriod);
 //            $('[name="confor"]').val(data[0].Conforme);
 //            $('[name="pro"]').val(data[0].ProjectID);
 //            $('#edit_form').modal('show');
 //            $('.modal-title').text('Edit Project Details');
        



 //          },
 //          error: function(jqXHR, textStatus, errorThrown)
 //          {
 //            alert('Error retrieving data');
 //          }
 //        });
 //       } 

 //    function save(){
 //      url = "<?php echo site_url('ProjectManagement/update')?>"
 //      form = '#editForm';

 //    $.ajax({
 //      url : url,
 //      type: "POST",
 //      data: $(form).serialize(),
 //      dataType: "JSON",
 //      success: function(data)
 //      {     

 //          $('#edit_form').modal('hide');
 //          alert('Project Details Updated!');
 //          location.reload();                       
 //      },
 //      error: function (jqXHR, textStatus, errorThrown)
 //      {
        // console.log(jqXHR);
      //   alert("Error getting data!");
  //     // }
  //   });
  // }
</script>


==================================================================================
PROJECT CONTROLLER
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class ProjectManagement extends CI_Controller {

 function __construct()
 {
   parent::__construct();
   $this->load->model('ProjMan_management_model','pmmm');
 }

 function index()
 {
 		if($this->session->userdata('logged_in')){
 		 $session_data = $this->session->userdata('logged_in');
    $data['userAccID'] = $this->session->userdata('logged_in')['userAccID'];
    $data['name'] = $this->session->userdata('logged_in')['name'];
    $data['access'] = $this->session->userdata('logged_in')['access'];
    $data['project'] = $this->pmmm->get_project();
     $data['emp'] = $this->pmmm->get_employee();
     $data['work'] = $this->pmmm->get_progwork();

     /*$data['pm_project'] = $this->pmmm->get_project_programwork2();*/
   $this->load->helper(array('form'));
   $this->load->view('projman_view');
 	}else
   {
     //If no session, redirect to login page
     redirect('home_view', 'refresh');
   }

 }
 

     public function ajax_view_program($project_id)
    {
    $data = $this->pmmm->get_by_project_id($project_id);
    echo json_encode($data);
    }

    public function ajax_view_project($project_id)
    {
    $data = $this->pmmm->get_by_project_id($project_id);
    echo json_encode($data);
    }

    public function update() 
 { 
    $data = array(
     'ProjectNo' => $this->input->post('proj_no'),
     'WorkerID' => $this->input->post('proj_sup'),
     'ProjectName' => $this->input->post('proj_name'),
     'Location' => $this->input->post('loc'),
     'ContractorCost' => $this->input->post('cont_cost'),
     'DateStarted' => $this->input->post('date_start'),
     'ContractPeriod' => $this->input->post('cont_per'),
     'Conforme' => $this->input->post('confor')) ;
         $this->pmmm->update_project(array('ProjectID' => $this->input->post('project_id')), $data);
         echo json_encode(array("status" => TRUE));
          
 }

 public function add_work(){
     
    $data = array(
    'ContractAmount' => $this->input->post('ContractAmount'),
    'ProjectID' => $this->input->post('proj_id'),
    'ProgramWorkID' => $this->input->post('ProgramWork')
    );

    $this->pmmm->add_work($data);
    redirect('ProjectManagement', 'refresh');
 }
}

?>

=============================================================================
PROJECT MODEL
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class ProjMan_management_model extends CI_Model {
	public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function get_progwork(){
        $this->db->select('*');
        $this->db->from('tbl_programwork');
        $query = $this->db->get();
        return $query->result();
    }

     public function get_project(){
        $this->db->from('tbl_projects p');
        $this->db->join('tbl_employee e', 'e.WorkerID = p.WorkerID', 'left');
        $query = $this->db->get();
        return $query->result();
    }

    public function get_by_projectid($project_id){
        $this->db->select('*');
        $this->db->from('tbl_projects p');
        $this->db->where('p.ProjectID', $project_id);
        $query = $this->db->get();
        return $query->result();
   }
     public function get_employee(){
        $this->db->from('tbl_employee');
        $query = $this->db->get();
        return $query->result();
    }

    public function update_project($where, $data)
   {
        $this->db->update('tbl_projects', $data, $where);
        return $this->db->affected_rows();
   }

    public function add_work($data){
        $this->db->insert('tbl_project_programwork',$data);
        return $this->db->insert_id();
    }

    public function get_by_project_id($project_id){
         $this->db->select('*');
        $this->db->from('tbl_projects p');
        $this->db->join('tbl_project_programwork pp', 'p.ProjectID = pp.ProjectID', 'left');
        $this->db->join('tbl_programwork pw', 'pw.ProgramWorkID = pp.ProgramWorkID', 'left');
        $this->db->where('p.ProjectID', $project_id);
        $query = $this->db->get();
        return $query->result();
    }

     public function get_project_programwork2(){
        $this->db->from('tbl_project_programwork pp');
        $this->db->join('tbl_projects p', 'p.ProjectID = pp.ProjectID', 'left');
        $this->db->join('tbl_programwork pw', 'pw.ProgramWorkID = pp.ProgramWorkID', 'left');
        // $this->db->where('pp.ProjectID = p.ProjectID');
        $this->db->where('pp.ProgramWorkID = pw.ProgramWorkID');
        $query = $this->db->get();
        return $query->result();
    }

}


What I have tried:

I have tried to pass it to another variable into the controller and made it private but it doesnt fix the problem. Badly need help here. Pls. Thank You!
Posted
Updated 29-Mar-18 20:16pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900