【问题标题】:How to Join Two Table In mysql database and Fetch Records.?如何在mysql数据库中加入两个表并获取记录。?
【发布时间】:2018-08-05 17:59:27
【问题描述】:

我想联合计划和 tag_category_banching 表。我想从计划和 tag_category_banching 中获得类似的结果。

Array
 (
 [0] => Array
   (
    [plan_id] => 3
    [plan_user_id] => 1
    [plan_title] => 3 Months
    [plan_validity] => 90
    [plan_desc] => 90 days
    [plan_activation] => 1
    [plan_status] => 1
    [banch_id] => 4
    [products_id] => 3
    [tag_cat_id] => 3
    [tag_cat_name] => 3 Months
    [nw_eb_mz_art_type] => 3
    [tag_cat_type] => 2
    [plan_price] => 200
)
[1] => Array
(
    [plan_id] => 4
    [plan_user_id] => 1
    [plan_title] => 1 Month
    [plan_validity] => 30
    [plan_desc] => 30 days.
    [plan_activation] => 1
    [plan_status] => 1
    [banch_id] => 3
    [products_id] => 3
    [tag_cat_id] => 4
    [tag_cat_name] => 1 Month
    [nw_eb_mz_art_type] => 3
    [tag_cat_type] => 2
    [plan_price] => 100
)
[2] => Array
(
    [plan_id] => 1
    [plan_user_id] => 1
    [plan_title] => 1 yr plan
    [plan_validity] => 365 days
    [plan_desc] => 365 days.
    [plan_activation] => 1
    [plan_status] => 1
    [banch_id] =>  
    [products_id] =>
    [tag_cat_id] => 
    [tag_cat_name] =>
    [nw_eb_mz_art_type] =>
    [tag_cat_type] =>
    [plan_price] =>
)

[3] => Array
(
    [plan_id] => 2
    [plan_user_id] => 1
    [plan_title] => 6 months plan
    [plan_validity] => 180 days
    [plan_desc] => 180 days.
    [plan_activation] => 1
    [plan_status] => 1
    [banch_id] =>  
    [products_id] =>
    [tag_cat_id] => 
    [tag_cat_name] =>
    [nw_eb_mz_art_type] =>
    [tag_cat_type] =>
    [plan_price] =>
)

)

在计划表中,在 tag_category_banching 表中未找到所有计划,然后在加入这些字段后,在 tag_category_banching 中的数据不匹配,如下面的数组。

【问题讨论】:

标签: php mysql codeigniter


【解决方案1】:
$query = $this->db->query("SELECT * FROM table-one JOIN table-two ON table-1-id = table-2-id");
return $query->result();

注意:- JOIN 和 ON 是获取两个表数据的关键字

表一和表二是你需要的表

AND table-one-id 和 table-two-id 是连接的两个表的列名

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多