dongmubi4444 2018-07-25 23:06
浏览 81
已采纳

类CI_DB_mysqli_result的对象无法转换为字符串?

hello i'm new in CodeIgniter, I've tried to read the documentation of CI but I still can't solve my problem, maybe someone here can help fix my problem. here my code:

$subdomain = $this->config->item('subdomain_name');
$instansi_id = $this->db->query("SELECT instansi_id FROM instansi WHERE subdomain = '$subdomain'");

$data = array(
'promosi'     => $this->db->query("SELECT * FROM gallery WHERE gallery_status = 1 AND instansi_id = $instansi_id ORDER BY gallery_created  DESC")->result(), 
'slide'       => $this->frontend->getSlide(),
),

i get an error like this: Object of class CI_DB_mysqli_result could not be converted to string

Maybe someone here can help to solve my problem ? Thanks.

  • 写回答

1条回答 默认 最新

  • doudu22272099831 2018-07-25 23:12
    关注

    In 2nd line you're getting query results which is an object [CI_DB_mysqli_result], but then you're just assuming it's a string in your next query.

    $instansi_id = $this->db->query("SELECT instansi_id FROM instansi WHERE subdomain = '$subdomain'")->row()->instansi_id;
    

    This should fix it.

    If not, just

    var_dump($instansi_id)
    

    To see what's in it and proceed from there.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部