dongmubi4444 2018-07-26 07: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-26 07: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.

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

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置