1

I am trying do pagination,which is working but dont know why my edit and delte functionality stopped working. This is My Controller

function view($page=0){
                $config = array();
                $config["base_url"] = base_url() . "index.php/employee/view";
                $config["total_rows"] = $this->employee_model->getTotalEmployeeCount();
                $config["per_page"] =5;
                $this->pagination->initialize($config);
                $this->data["results"] = $this->employee_model->getEmployee($config["per_page"], $page);
                $this->data["links"] = $this->pagination->create_links();
                $this->data['title'] = 'Payroll System';
                $this->data['message'] = $this->session->flashdata('message');
                $this->load->view('employee_view', $this->data);

    }

This is My Model

function getTotalEmployeeCount() {
            return $this->db->count_all('user');
        }
      function getEmployee($limit, $start) {
            $this->db->limit($limit, $start);
            $this->db->select('id,firstname,lastname,presentadress,contactno,dateofjoining,email');
            $qry= $this->db->get('user');
        return $qry->result_array();
         }

This is my view

 <?php
    foreach ($results as $m){
    ?>
      <tr style="text-align:center;">
                  <td><?php echo $m['id'] ?></td>
                  <td><?php echo $m['firstname'] ?></td>
                  <td><?php echo $m['lastname'] ?></td>
                  <td><?php echo $m['dateofjoining'] ?></td>
                  <td><?php echo $m['presentadress'] ?></td>
                  <td><?php echo $m['contactno'] ?></td>
                  <td><?php echo $m['email'] ?></td>
   <td><a href="<?php echo site_url('employee/edit_employee/'.$m->id) ?>" class="btn btn-primary btn-mini">Edit</a></td>
          <td>
          <?php 
          echo anchor('employee/delete_employee/'.$m->id, 'Delete', array('onClick' => "return confirm('Are you sure you want to delete?')"));
          ?>
          </td>
    <?php
    }
    ?>
    <?php echo $this->pagination->create_links()?>

In my model if change result_array to result then it gives error of "Cannot use object of type stdClass as array in".Thats why i used result_array,But now delete and edit functionality not working.I am getting the error of "Trying to get property of non object". Help me to end this error

3 Answers 3

3

If you change result from result_array in model, in view you should access those elements like this.

<td><?php echo $m->id; ?></td>
<td><?php echo $m->firstname; ?></td>
<td><?php echo $m->lastname; ?></td>
Sign up to request clarification or add additional context in comments.

1 Comment

Move echo $this->pagination->create_links(); to above the <table>.
1

Just try like this

<td><?php echo $m->id; ?></td>
<td><?php echo $m->firstname; ?></td>
<td><?php echo $m->lastname; ?></td>

Comments

0

change single line in your view :

<?php
    foreach ($results as $m){
    ?>
      <tr style="text-align:center;">
                  <td><?php echo $m['id'] ?></td>
                  <td><?php echo $m['firstname'] ?></td>
                  <td><?php echo $m['lastname'] ?></td>
                  <td><?php echo $m['dateofjoining'] ?></td>
                  <td><?php echo $m['presentadress'] ?></td>
                  <td><?php echo $m['contactno'] ?></td>
                  <td><?php echo $m['email'] ?></td>
   <td><a href="<?php echo site_url('employee/edit_employee/'.$m->id) ?>" class="btn btn-primary btn-mini">Edit</a></td>
          <td>
          <?php 
          //change  here ///
          echo anchor('employee/delete_employee/'.$m['id'], 'Delete', array('onClick' => "return confirm('Are you sure you want to delete?')"));
          ?>
          </td>
    <?php
    }
    ?>
    <?php echo $this->pagination->create_links()?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.