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条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?