dourui7186 2013-08-14 04:52
浏览 37
已采纳

类stdClass的对象无法转换为字符串,并且分页无法正常工作

Finally my pagination worked.Still there are some problems.In every page its showing only one data and edit delete functionality not working.I tried changing almost everything.Any guidance will be great. *This is my controller*

function view($page=0){
        $config = array();
                $config["base_url"] = base_url() . "index.php/view_expenses/view";
                $config["total_rows"] = $this->emp_expenses_model->getTotalStudentCount();
                $config["per_page"] = 5;
                $this->pagination->initialize($config);
                $this->data["results"] = $this->emp_expenses_model->getStudent($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('view_expenses', $this->data);

    }

This is the code in my model

function getTotalStudentCount() {
            return $this->db->count_all("emp_expenses");
        }
      function getStudent($limit, $start) {
            $this->db->limit($limit, $start);
            $qry= $this->db->get("emp_expenses");
        return $qry->result();
         }

and this is the view

    <table cellspacing="0" cellpadding="2" border="0" id="tbl"  style="width:100%">
    <tr style="background-color:#045c97">
          <td class="heading">Expenses ID</td>
          <td class="heading">Employee ID</td>
          <td class="heading">Drop Down</td>
          <td class="heading">Mode OF Payment</td>
          <td class="heading">Amount</td>
          <td class="heading">Edit</td>
          <td class="heading">Delete</td>
    </tr>
     <?php
    foreach($results as $m)
      //var_dump($results);die('asd');
      ?> 
      <tr style="text-align:center;">
         <tr>
          <td><?php  echo $m->expenses_id ?></td>
          <td><?php  echo $m->id ?></td>
          <td><?php  echo $m->dropdown ?></td>
          <td><?php  echo $m->modeofpayment ?></td>
          <td><?php  echo $m->amount ?></td>
          <td><a href="<?php echo site_url('view_expenses/edit_expenses/'.$m) ?>"class="btn btn-primary btn-mini">Edit</a></td>
          <td>
          <?php 
          echo anchor('view_expenses/delete_expenses/'.$m, 'Delete', array('onClick' => "return confirm('Are you sure you want to delete?')"));
          ?>
          </td>
      </tr>
       <?php echo $this->pagination->create_links()?>
</table>
  • 写回答

1条回答 默认 最新

  • douhan4812 2013-08-14 05:04
    关注

    Firstly, probably not related to the main problem but your class="" attribute on the edit button has no space between the start of the attribute and the closing quotes of the href.

    The main problem seems to be that your trying to echo $m, on this line:

    <?php echo site_url('view_expenses/edit_expenses/'.$m) ?>
    

    $m is an object (containing multiple variables of information), your getting an error because your trying to treat it like a string.

    Instead, you need to access one of these variables from within the object, just like you do further up in the code. I am guessing, you want the id, which would be $m->id.

    Give this a go instead:

    <?php echo site_url('view_expenses/edit_expenses/'.$m->id) ?>
    

    The same goes for your delete button.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?