douou5933 2018-06-04 08:40
浏览 40

如何将mysql_fetch_array转换为CodeIgniter

I have a problem,im trying to convert php standard to CodeIgniter, But I dont know how to convert ths code, please help, and thanks a lot.

    <?php
    mysql_connect("localhost", "root", "");
    mysql_select_db("ardefa");
    $borneo=mysql_query("select* from borneo");

    while($row=mysql_fetch_array($borneo))
    {
       ?>
         <a href="#"><li><img src="
         <?php 
         $page = isset($_GET['page']) ? ($_GET['page']):"";

         if ($page =='borneo')
         {
            echo $row["img"];
         }
         ?>">
         </li></a>
    <?php
    }
    ?>
  • 写回答

2条回答

  • doudun3040 2018-06-04 08:49
    关注

    Hope this will help you :

    You don’t need to use db_select if you have single database, if multiple database you only need to use a different database on the same connection. You can switch to a different database when you need to using this $this->db->db_select('ardefa');

    You can do like this :

    //$this->db->db_select('ardefa');
    $this->db->select('*');
    $this->db->from('borneo');
    $query = $this->db->get();
    if ($query->num_rows() > 0 )
    {
       /*for multiple array*/
    
       $result = $query->result_array();
       /*print here to see the result
       print_r($result);
       */
    }
    

    Use $result like this :

    foreach($result as $row)
    {
        echo $row;
    }
    

    Or can also do it like this :

    //$this->db->db_select('ardefa');
    $query = $this->db->get('borneo');
    if ($query->num_rows() > 0 )
    {
       /*for multiple array*/
    
       $result = $query->result_array();
       /*for single array
       $row = $query->row_array();
       */
    }
    

    For more : https://www.codeigniter.com/user_guide/database/

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料