douxuanou2787 2014-12-14 16:38
浏览 49
已采纳

如何使用codeigniter从数据库中检索值

Controller

public function index()
{

    $config["base_url"] = base_url() . "index.php/admin_requirements/index";
    $config["total_rows"] = $this->admin_requirements_full->record_count();
    $config['per_page'] = 5;
    $this->pagination->initialize($config);
    $page = $this->uri->segment(3);

    $data['results'] = $this->admin_requirements_full->display($config["per_page"], $page);
    $data['links'] = $this->pagination->create_links();

    $session_data = $this->session->userdata('logged_in');
    $data['username'] = $session_data['username'];

    $this->load->view('adminpanel/header',$data);
    $this->load->view('adminpanel/menubar');
    $this->load->view('adminpanel/footer');
}

Model

function display($limit, $start)
{

    $this->db->limit($limit, $start);
    $query  =   $this->db->get('db_requirements');
    return $query->result();
}

public function record_count() 
{
    return $this->db->count_all("db_requirements");
}

View

<?php
    foreach($results as $data) 
    {
?>
    <tr align="center">
        <td height="29"><?php echo $data->id; ?></td>
        <td><?php echo $data->cat_id; ?></td>
        <td><?php echo $data->subcat_id; ?></td>
        <td><?php echo $data->city; ?></td>
        <td><?php echo $data->email_id; ?></td>
        <td><?php echo $data->phone; ?></td>
        <td><?php echo $data->publish; ?></td>
        <td>Delete</td>
    </tr>
<?php
    }
?>
</table>
<p class="pages">Pages : <?php echo $links; ?></p>

Result

[Sl.No] [category] [subcategory]
1               1               1
2               3               1

In the above result CATEGORY and SUBCATEGORY fields are in numerals. The actual value of these numbers are stored in another database table.

My question is , how can i retreive actual value for the above numbers.

My CATEGORY and SUBCATEGORY databse are given below.

// db_bus_category

id, item

// db_bus_subcategory

id, cat_id, subcat_id, item
  • 写回答

1条回答 默认 最新

  • doujia9833 2014-12-14 18:06
    关注

    If you need to get values from other tables you will need to use an SQL JOIN. A cursory glance at the active record section of the codeigniter documentation shows a function $this->db->join();

    https://ellislab.com/codeigniter/user-guide/database/active_record.html

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

报告相同问题?

悬赏问题

  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题