php - 选择并插入多条记录

标签 php mysql codeigniter

------------------------------------------------
ID  |   Member Name |   Zone    | Created_Date |
------------------------------------------------
1   |   foo         |   Zone1   |  2015-02-23  |
2   |   bar         |   Zone1   |  2015-02-23  |
3   |   foo1        |   Zone2   |  2015-02-23  |
4   |   baar1       |   Zone2   |  2015-02-23  |
5   |   foo3        |   Zone1   |  2015-02-23  |
------------------------------------------------

------------------------------------------------------------
ID  |   Member ID   |    Car    |   Zone    | Created_Date |
------------------------------------------------------------
1   |   1           |   Civic   |   Zone1   |  2015-02-23  |
2   |   1           |   BMW     |   Zone2   |  2015-02-23  |
3   |   2           |   Vitz    |   Zone1   |  2015-02-23  |
4   |   2           |   BMW     |   Zone1   |  2015-02-23  |
5   |   3           |Honda City |   Zone2   |  2015-02-23  |
------------------------------------------------------------

我想在分类帐中输入一些条目以防止在区域内注册汽车

喜欢

今天在 1 区注册了多少张卡?

我可以处理单个区域,但如何管理多个项目

我正在使用 codeigniter 并尝试这样

public function distribute_commision()
{
    $this->db->where('Is_Active', 0);
    //$this->db->where('Sort_Order', 4);
    $this->db->select('ID');                
    $this->db->select('Zone');
    $this->db->where('Created_Date', '2015-02-23');
    $query = $this->db->get('tbl_clients');

    if($query->num_rows() > 0)
    {
        $data = $query->result_array();

        foreach($data as $da)
        {
            $array = "'". $da['Zone'] ."'";
            $zone[] = $array;
        }

        $record = implode(",", $zone);
        //echo $record;
        $zm_query = $this->db->query("SELECT `ID`, `Name`, `Zone` FROM `tbl_members` WHERE `Zone` IN (".$record.") AND `Sort_Order` = '4' AND `Created_Date` = '".date('Y-m-d', time())."'");
        echo "<pre>";
        print_r($zm_query->result_array());
        echo "</pre>";          
    }   

}

最佳答案

尝试这个查询

select *,count(aa.id) as count tbl_client as aa
join tbl_members as bb on bb.id=aa.member_id
where aa.created_date=date('Y-m-d', time())
group by aa.created_date

关于php - 选择并插入多条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28667244/

相关文章:

mysql - 从 Codeigniter 中的相关表获取数据——将 MySQL 查询转换为 CI MVC

sql - 使用 codeigniter 和 ajax 检查数据库中是否存在用户名

c# - 主异常/碰撞检查

php - HTML/PHP 表单不向 MySQL 数据库发送数据

php - 使用 JQuery 和 CodeIgniter 将注释安全地写入数据库?

php - nodejs中的加密

mysql - 从 MySQL 迁移到 AWS DynamoDB? 5m 行,4 个表,1k 写入 p/s

php - 有没有办法为每个虚拟主机设置不同的 PHP 模块?

php - 如何获取 stdClass 对象 foreach 循环的值

php - Magento 不正确的 404 重定向