如何查询(fetch)一个多表的mysql数据库作为单个表在codeigniter [英] How to query (fetch) a multiple table of mysql database as a single table in codeigniter

查看:101
本文介绍了如何查询(fetch)一个多表的mysql数据库作为单个表在codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个数据库表

第一

vedd_plan_task ::
task_id | task name

第二

  plan_task_mapping ::
  task_mapp_id | plan_id | task_id

第三

tbl_plan ::
plan_id | plan_title | plan_price | plan_desc

在这个表中,我映射了第二个表与第一&第三。 (2表的值来自第1和第3)

In this table i mapped the 2nd table with 1st & 3rd. (2 table's value come from 1st & 3rd)

PLAN 我从 PLAN TASK 。并在两个不同的表中提交数据。
现在我必须显示数据库作为表,但我找不到方式获得一个task_name表单映射表。

for PLAN i call the data from PLAN TASK tbl. and submit the data in two different table. now i have to show the database as table but i can't find the way to get a task_name form mapping table.

我想要一个包含此字段的表格

I want a table with this field

Plan_id | plan_title | plan_price | plan_desc | task_name(在特定计划id之前插入的)。

Plan_id | plan_title | plan_price | plan_desc | task_name (which i inserted before with particular plan id)..

推荐答案

$query = $this->db->query('SELECT tbl_plan.plan_id ,plan_title ,plan_price ,plan_desc ,task_name,plan_task_mapping.task_id FROM tbl_plan LEFT JOIN plan_task_mapping ON plan_task_mapping.plan_id = tbl_plan.plan_id LEFT JOIN vedd_plan_task ON vedd_plan_task.task_id = plan_task_mapping.task_id');

foreach ($query->result() as $row) {    

echo $row->plan_id; 
echo $row->plan_title;
echo $row->plan_price;
echo $row->plan_desc;
echo $row->task_name; 
echo $row->task_id; 

} ?>

这篇关于如何查询(fetch)一个多表的mysql数据库作为单个表在codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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