PHP两表关联查询操作

werwerds 发布于 2016/06/20 16:52
阅读 294
收藏 0
PHP

第一个表的typeid对应第二个表的id,time是对应表1的signedtime,typeid相同的合并,怎么才能得到这样的结果:

Array
(
    [0] => Array
        (
            [activity_id] => 2
            [name] => 王
            [mobile] => 
            [signed] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [activityid] => 2
                            [activityname] => 测试数据2多次签到
                            [signedname] => 一次签到
                            [create_time] => 1465181547
                            [listorder] => 0
                            [sign_img] => 
                            [type] => 
                            [time] =>1463056434
                        )

                    [1] => Array
                        (
                            [id] => 3
                            [activityid] => 2
                            [activityname] => 测试数据2多次签到
                            [signedname] => 二次签到
                            [create_time] => 1465182225
                            [listorder] => 0
                            [sign_img] => 
                            [type] => 
                            [time] =>1463074455
                        )

                    [2] => Array
                        (
                            [id] => 4
                            [activityid] => 2
                            [activityname] => 测试数据2多次签到
                            [signedname] => 三次签到
                            [create_time] => 1465189536
                            [listorder] => 0
                            [sign_img] => 
                            [type] =>
                            [time]=> 
                        )            

                )

        )

    [1] => Array
        (
            [activity_id] => 2
            [name] => zhang
            [mobile] => 
            [signed] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [activityid] => 2
                            [activityname] => 测试数据2多次签到
                            [signedname] => 一次签到
                            [create_time] => 1465181547
                            [listorder] => 0
                            [sign_img] => 
                            [type] => 
                            [time] =>
                        )

                    [1] => Array
                        (
                            [id] => 3
                            [activityid] => 2
                            [activityname] => 测试数据2多次签到
                            [signedname] => 二次签到
                            [create_time] => 1465182225
                            [listorder] => 0
                            [sign_img] => 
                            [type] =>
                            [time] =>
                        )

                    [2] => Array
                        (
                            [id] => 4
                            [activityid] => 2
                            [activityname] => 测试数据2多次签到
                            [signedname] => 三次签到
                            [create_time] => 1465189536
                            [listorder] => 0
                            [sign_img] => 
                            [type] => 
                            [time]=>1463036123
                        )

                   
                )

        )

)




加载中
0
纵使有花兼明月何堪无酒亦无人
纵使有花兼明月何堪无酒亦无人
select * from tables1 as t1 
left join tables2 t2 on t1.typeid = t2.id




0
工兵铲
工兵铲
这是sql的问题,关php什么事啊
返回顶部
顶部