dongyu8694 2019-03-25 14:24
浏览 79
已采纳

尝试从数据库中获取列值时获取非对象错误的属性

Hi I am trying to fetch the column value from the database my preview section so that each content is fetched on web page via database. I have matched my one table id to the the another table id and get the entire row as a result and save it in a variable and try to select a selective value from that row to show on my web page. But when i try to fetch the value of selective column the notice error was appeared on my page saying " Trying to get property of non-object". Please help me in this. Here is my codes:-

My view page code is:-

<ul>
    <li><p> <?= $seller->Name; ?></p></li>
    <li><p> <?= $switch->return_policy; ?> Return Policy</p></li>
    <li><p>Replacement  <?= $switch->replacement; ?> </p></li>
    <li><p>Cash On Delivery <?= $switch->cod; ?></p></li>       
</ul>    

The error shows in this line <li><p> <?= $seller->Name; ?></p></li>

My controller code was:-

public function Preview_Switch($switch_id)
   {
    if($this->session->userdata('seller_username') == "" && $this- 
               >session->userdata('seller_password') == ""){
        return redirect('seller/index');
    }
    else
    {
        $result = $this->sm->Preview_Switch($switch_id);
        $seller_id = $result->seller_id;
        $seller = $this->sm->Get_Seller_Info($seller_id);
        if($result)
        {
             $this->load->view('seller/Work_List/Switch_Preview', 
             ['switch'=>$result, 'seller'=>$seller]);
        }
    }
}

And my Model code is:-

enter code here
public function Get_Seller_Info($seller_id)
{
$get_seller_info = $this->db->get_where('seller',['Id'=>$seller_id]);
if($get_seller_info->num_rows > 0)
    {
        return $get_seller_info->row();
    }
    else
    {
        return false;
    }
}

The error shows only in seller table while I can get a value fro the switch table.

  • 写回答

2条回答 默认 最新

  • dounuo7954 2019-03-25 16:49
    关注

    Change :

    if($get_seller_info->num_rows > 0)
    

    to :

    if($get_seller_info->num_rows() > 0)
    

    Reference :
    query->num_rows versus query->num_rows()
    codeigniter issue with num_rows (possible bug?)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 c语言,请帮蒟蒻看一个题
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)