TinyButStrong通过动态和循环问题创建了动态

时间:2015-07-20 05:34:40

标签: php html codeigniter tinybutstrong

我想在日历表视图中创建员工的休假报告作为附加图像。

enter image description here

我从控制器中获取了员工并存储在和数组中 同样地,我在控制器中获取日期(基于选定的年份和月份)并存储在数组中 基于这个员工和日期,我正在获取每个员工的叶子并存储在一个数组中。

控制器

    $month = 7;
    $year = 2015;
            for($d=1; $d<=31; $d++)//for dynamic dates as displayed in image
            {
                $time=mktime(12, 0, 0, $month, $d, $year);          
                if (date('m', $time)==$month)       
                $this->data['blk4'][]['date']=date('d', $time);
                $this->data['blk5'][]['day']=date('D', $time);
                $this->data['blk6'][]['fulldates']=date('Y-m-d',$time);
            }
            $data['employee'] = $this->teamprofile_model->allTeamMembers('team_profile_full_name', 'ASC');//fetching all amployee

            foreach($data['employee'] as $d)//for each employee checking the leave
            {
                foreach($this->data['blk6'] as $date)//for each date
                {   
                    $this->db->where('employee_id',$d['team_profile_id']);
                    $this->db->where('leave_date',$date['dates']);
                    $Q=$this->db->get('leave_reports');
                    if($Q->num_rows() > 0)
                    {
                        foreach ($Q->result_array() as $row)
                        {
                            $data1[] = $row;
                        }
                    }
                    $this->data['blk8'][]['leave'] = $data1[0]['leave_time'];//stored leave of each employee in this array
                    $data1="";
                }
            }

HTML

<table class="footable table table-bordered table-hover" border="1">
      <thead>
             <tr>
                 <th>Employee</th>//display employee
                 <th><!--[blk4.date;block=th;comm]--><br/><!--[blk5.day;block=th;comm]--></th> //display dates as displying in above image
            </tr>
       </thead>
       <tbody class="">
            <tr>
                <td><!--[blk7.all_team_members;block=tr;comm]--></td>//dynamic employee list
                <td>here i want to display the leave stored in [blk8.leave]</td>                     
            </tr>
       </tbody>
</table>

但问题是[blk8.leave]存储了每个日期的所有员工离开,所以如果我将其打印为[blk8.leave; block = td; comm],那么它会在一行中打印所有数组值。我想在月结束日期31之后打破这个数组。

enter image description here

输出应为:

enter image description here

1 个答案:

答案 0 :(得分:1)

问题是你的假数据是线性结构的,但它需要与日期相关联。

TBS(TinyButStrong)作为内置功能,用于将表与动态列(或其他类似结构)合并。

下面的示例与您的问题非常相似,您可以轻松地进行调整。 http://www.tinybutstrong.com/examples.php?e=dyncol1

但是应该修改数据的结构。 以下是数据如何的示例:

        $blk7 = array();
        foreach($data['employee'] as $d)//for each employee checking the leave
        {
            $employee = array(
                'team_profile_id' => $d['team_profile_id'],
                'all_team_members' => $d['all_team_members'],
            );
            foreach($this->data['blk6'] as $date)//for each date
            {   
                $this->db->where('employee_id',$d['team_profile_id']);
                $this->db->where('leave_date',$date['dates']);
                $Q=$this->db->get('leave_reports');
                if($Q->num_rows() > 0)
                {
                    foreach ($Q->result_array() as $row)
                    {
                        $data1[] = $row;
                    }
                }
                $column = 'leave_' . $date['dates'];
                $employee[$column] = $data1[0]['leave_time'];//stored leave of each employee in this array
                $data1="";
            }
            $blk7[] = $employee;
        }
相关问题