亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

致命錯誤:不能在第 38 行的 C:\xampp\htdocs\ov400\applicatio

致命錯誤:不能在第 38 行的 C:\xampp\htdocs\ov400\applicatio

PHP
三國紛爭 2022-07-16 17:06:00
我收到錯誤致命錯誤:不能使用 stdClass 類型的對象作為我的控制器名稱中的數組是 Useraccountfunction userList() {      $result['data'] = $this->Useraccount_mod->getUser_list();   $data['userlist']=$result['data'] ;   $this->load->view('Useraccount/Userlist', $data);}模型名稱是 Useraccount_modfunction getUser_list() {    $query=$this->db->query("select * from users");    return $query->result();}和視圖名稱是用戶列表<tbody>    <?php    if ($userlist > 0) {        foreach ($userlist as $row) {            ?>            <tr>                                                        <td width="100"><?php echo $row['username']; ?></td>                 <td width="100"><?php echo $row['name']; ?></td>                 <td width="100"><?php echo $row['address']; ?></td>                 <td width="100"><?php echo $row['creatdate']; ?></td>                 <td width="100"><?php echo $row['updateddate']; ?></td>             </tr>            <?php        }    } else {        ?>        <tr>            <td colspan="3" align="center"><strong>No Record Found</strong></td>        </tr>        <?php    }    ?></tbody>遇到 PHP 錯誤 嚴重性:錯誤消息:不能使用 stdClass 類型的對象作為數組文件名:Useraccount/Userlist.php 行號:38 回溯:
查看完整描述

1 回答

?
FFIVE

TA貢獻1797條經驗 獲得超6個贊

您正在使用result()函數來獲取記錄,但這會將記錄作為對象而不是數組。如果要獲取數組,則必須使用result_array()。


function userList() {   

   $data['userlist'] = $this->Useraccount_mod->getUser_list();

   $this->load->view('Useraccount/Userlist', $data);

}

方法一:


function getUser_list() {

  $query = $this->db->query("select * from users")->result_array(); //here we can use result() as well but it gives object not array

  return $query;

}



<tbody>

  <?php

  if ($userlist > 0) {

      foreach ($userlist as $row) {

          ?>

          <tr>                                        

              <td width="100"><?php echo $row['username']; ?></td> 

              <td width="100"><?php echo $row['name']; ?></td> 

              <td width="100"><?php echo $row['address']; ?></td> 

              <td width="100"><?php echo $row['creatdate']; ?></td> 

              <td width="100"><?php echo $row['updateddate']; ?></td> 

          </tr>

          <?php

      }

  } else {

      ?>

      <tr>

          <td colspan="3" align="center"><strong>No Record Found</strong></td>

      </tr>

      <?php

  }

  ?>

</tbody>

方法二:


function getUser_list() {

  $query = $this->db->query("select * from users")->result(); 

  return $query;

}



<tbody>

  <?php

  if ($userlist > 0) {

      foreach ($userlist as $row) {

          ?>

          <tr>                                        

              <td width="100"><?php echo $row->username; ?></td> 

              <td width="100"><?php echo $row->name; ?></td> 

              <td width="100"><?php echo $row->address; ?></td> 

              <td width="100"><?php echo $row->creatdate; ?></td> 

              <td width="100"><?php echo $row->updateddate; ?></td> 

          </tr>

          <?php

      }

  } else {

      ?>

      <tr>

          <td colspan="3" align="center"><strong>No Record Found</strong></td>

      </tr>

      <?php

  }

  ?>

</tbody>


查看完整回答
反對 回復 2022-07-16
  • 1 回答
  • 0 關注
  • 106 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號