codeigniter join 2 表数据 [英] codeigniter join 2 table data

查看:34
本文介绍了codeigniter join 2 表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是 codeigniter 的新手,目前正在项目中的一个小项目中工作,我正在尝试连接两个表并在单个表中显示其中的数据.我查看了 codeigniter 的用户指南,但我不确定这是如何工作的

hi everyone i am new to codeigniter and currently working on a small project in the project i am trying to join two tables and display there data in single table. i looked at the user guide that codeigniter has an i am not sure how this work

$this->db->join();

首先应该是什么表,应该首先是什么 id 键.如果可以的话,有人可以更详细地解释我吗,请使用示例.我正在尝试加入凭证表和 tblanswers.Tnx 用于回答.

what table should be first and what id key should be firs. Can someone explain me more in detail about this please use examples if u can. I am trying to join credential table and tblanswers. Tnx for answering.

我尝试使用此示例编写函数:

i have tried to code a function using this example:

$this->db->select('*');
$this->db->from('blogs');
$this->db->join('comments', 'comments.id = blogs.id');

$query = $this->db->get();

是否可以使用简单的函数来分别检索两个表数据,而不是在 codeigniter 中使用 join 方法?我想要的只是将数据库表中的数据回显到我网站页面中要显示的 html 表中是否可以编写两个 get 函数来分别检索两个表?

instead of using join method in codeigniter is it possible to use a simple function to retrieve the two table data separately? all i want is to echo the data from database table on to a html table in my website page to be displayed is it possible to write two get functions to retrieve two tables separately ?

推荐答案

先放哪个表并不重要... 简单地说:

It doesn't matter what table is first... Simply:

<?php

$this->db->select('t1.name, t2.something, t3.another')
     ->from('table1 as t1')
     ->where('t1.id', $id)
     ->join('table2 as t2', 't1.id = t2.id', 'LEFT')
     ->join('table3 as t3', 't1.id = t3.id', 'LEFT')
     ->get();
?>

这篇关于codeigniter join 2 表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆