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

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

问题描述

hi大家我是新的codeigniter,目前正在一个小项目中的项目,我试图连接两个表,并显示单个表中的数据。我看过用户指南codeigniter有一个我不知道这是如何工作



$ this-> db-> join ;



什么表应该是第一个,什么id键应该是firs。有人可以解释我更详细这个请使用示例,如果你可以。我试图加入证书表和tblanswers。

 <$> 

我已尝试使用此示例对函数进行编码。 c $ c> $ this-> db-> select('*');
$ this-> db-> from('blogs');
$ this-> db-> join('comments','comments.id = blogs.id');

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

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

 < ?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()


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();

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();

EDIT: 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 does not matter what 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天全站免登陆