【问题标题】:This is my MySQL query, how to write in CodeIgniter?这是我的 MySQL 查询,如何在 CodeIgniter 中编写?
【发布时间】:2017-06-13 00:40:24
【问题描述】:

这是我的 MySQL 查询以及如何在 CodeIgniter 中编写它

SELECT distinct a.user_name
FROM wl_customers a
    INNER JOIN tbl_bid b ON a.customers_id = b.customers_id
    INNER JOIN tbl_portfolio c ON b.portfolio_id=c.portfolio_id 
WHERE c.portfolio_id='16'

【问题讨论】:

标签: php mysql codeigniter


【解决方案1】:

像这样尝试。使用表之间的连接。

<?php

$query = $this->db->distinct()
        ->select('a.user_name')
        ->from('wl_customers as a'); 
        ->join('tbl_bid as b','a.customers_id=b.customers_id');
        ->join('tbl_portfolio as c','b.portfolio_id=c.portfolio_id')
        ->where('c.portfolio_id',16)
        ->get();
print_r($query->result_array);//array of your records

更多阅读文档https://www.codeigniter.com/userguide3/database/query_builder.html

【讨论】:

  • 请不要因为你给他的密码让他觉得懒惰。让他先试试,你再帮他
  • 希望他能从这里学到一些东西,下次再创佳绩。
  • 你是个好摩托车。但至少如果他还是个孩子,我们可以让他走路,但到目前为止他还没有在 CI 中尝试过任何事情。这就是我告诉你的原因。谢谢..
【解决方案2】:

使用活动记录

    $this->db->select('distinct a.user_name');
    $this->db->from('wl_customers as a'); 
    $this->db->join('tbl_bid as b','a.customers_id=b.customers_id');
    $this->db->join('tbl_portfolio as c','b.portfolio_id=c.portfolio_id');
    $this->db->where('c.portfolio_id',16,false);
    $query = $this->db->get();

【讨论】:

    【解决方案3】:
    $query = $this->db->query("
    SELECT MAX(A.BID),B.* FROM tbl_bid A INNER JOIN wl_customers B ON A.customers_id=B.customers_id
    WHERE portfolio_id='16'
    ");
    

    【讨论】:

    • 这很麻烦,你应该使用Query Builder类并按照@Rohan的建议阅读文档。
    • CI 不会强制您使用查询生成器,尤其是。如果你已经有工作的 sql。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-18
    • 2016-07-17
    • 2016-04-23
    • 2011-09-13
    • 2015-10-19
    • 2017-11-18
    相关资源
    最近更新 更多