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.

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

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改