TinyButStrong created dynamic <th> with dynamic <tr> and <td> looping issue
TinyButStrong created dynamic <th> with dynamic <tr> and <td> looping issue
我想在日历中创建员工的休假报告 table 查看附件图像。
我已经从控制器中获取员工并存储在数组中。
我以同样的方式在控制器中获取日期(基于选定的年份和月份)并存储在数组中。
基于这个员工和日期,我正在获取每个员工的叶子并存储在一个数组中。
控制器
$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 月的结束日期之后打破这个数组。
输出应该是:
问题是您的休假数据是线性结构的,而它需要与日期相关联。
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;
}
我想在日历中创建员工的休假报告 table 查看附件图像。
我已经从控制器中获取员工并存储在数组中。
我以同样的方式在控制器中获取日期(基于选定的年份和月份)并存储在数组中。
基于这个员工和日期,我正在获取每个员工的叶子并存储在一个数组中。
控制器
$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 月的结束日期之后打破这个数组。
输出应该是:
问题是您的休假数据是线性结构的,而它需要与日期相关联。
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;
}