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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘