Codeigniter日历:向单元格添加特定数据
这是我的问题 我需要向所有人展示选定月份的生日,我已经了解了如何将数据放在特定的表格单元格中,唯一的问题是,数据也出现在其他表格单元格中,这是不需要的。在下图中,Codeigniter日历:向单元格添加特定数据,codeigniter,codeigniter-2,Codeigniter,Codeigniter 2,这是我的问题 我需要向所有人展示选定月份的生日,我已经了解了如何将数据放在特定的表格单元格中,唯一的问题是,数据也出现在其他表格单元格中,这是不需要的。在下图中,Ori Hendricks只能在2上,但它会出现在其他单元格中 这是日历的数据 Array ( [2] => Array ( [0] => Nomlanga Bentley**81 [1] => Ori Hendricks**325
Ori Hendricks
只能在2
上,但它会出现在其他单元格中
这是日历的数据
Array
(
[2] => Array
(
[0] => Nomlanga Bentley**81
[1] => Ori Hendricks**325
)
[5] => Array
(
[0] => Rina Nash**161
)
[10] => Array
(
[0] => Gary Mullins**252
)
[12] => Array
(
[0] => Nissim Donovan**207
)
[13] => Array
(
[0] => Harper Trevino**380
)
[14] => Array
(
[0] => Sacha Arnold**167
[1] => Wade Hughes**322
[2] => Brennan Long**3
)
[15] => Array
(
[0] => Gary Hart**290
)
[21] => Array
(
[0] => Alisa Bowman**201
)
[22] => Array
(
[0] => Dustin Meyers**330
)
[26] => Array
(
[0] => Ifeoma Swanson**331
)
[28] => Array
(
[0] => McKenzie Norton**327
[1] => Asher Rasmussen**47
)
[29] => Array
(
[0] => Branden Conway**7
[1] => Luke Sullivan**176
)
[30] => Array
(
[0] => Slade Moon**16
)
)
Iv'e创建了一个MY_calendar
类并创建了自己的生成器,下面是显示单元格数据的相关代码
if (isset($data[$day]))
{
// Cells with content
$temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_content_today'] : $this->temp['cal_cell_content'];
if(is_array($data[$day]))
{
foreach($data[$day] as $k => $v)
{
$name = substr($v,0,strpos($v,'**'));
$student_enrollment_id = substr($v,strpos($v,'**')+2);
$data_formatted[$k] = '<a href="'.site_url('profile/student/'.$student_enrollment_id).'" target="_blank" class="btn btn-mini">'.trim($name).'</a>';
}
$data_from_array = implode('',$data_formatted);
$out .= str_replace('{day}', $day, str_replace('{content}', $data_from_array, $temp));
}else{
$out .= str_replace('{day}', $day, str_replace('{content}', $data[$day], $temp));
}
}
else
{
// Cells with no content
$temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_no_content_today'] : $this->temp['cal_cell_no_content'];
$out .= str_replace('{day}', $day, $temp);
}
if(isset($data[$day]))
{
//有内容的单元格
$temp=($is_current_month==TRUE,$day==cur_day)?$this->temp['cal_cell_content_today']:$this->temp['cal_cell_content'];
if(是_数组($data[$day]))
{
foreach($data[$day]为$k=>$v)
{
$name=substr($v,0,strpos($v,***');
$student_enrollment_id=substr($v,strpos($v,'**')+2);
$data_格式化[$k]='';
}
$data\u from\u array=内爆(“”,$data\u格式化);
$out.=str_replace('{day}',$day,str_replace('{content}',$data_from_array,$temp));
}否则{
$out.=str_replace('{day}',$day,str_replace('{content}',$data[$day],$temp));
}
}
其他的
{
//没有内容的单元格
$temp=($is_current_month==TRUE,$day==cur_day)?$this->temp['cal_cell_no_content_today']:$this->temp['cal_cell_no_content'];
$out.=str_replace('{day}',$day,$temp);
}
我不知道该怎么做,请帮忙。问题发生了,因为数组索引仍然保存着上一个循环的值 只需在上面粘贴的MY_calendar类代码片段中稍作更改:
<?php
if (isset($data[$day]))
{
// Cells with content
$temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_content_today'] : $this->temp['cal_cell_content'];
if(is_array($data[$day]))
{
foreach($data[$day] as $k => $v)
{
$name = substr($v,0,strpos($v,'**'));
$student_enrollment_id = substr($v,strpos($v,'**')+2);
$data_formatted[$k] = '<a href="'.site_url('profile/student/'.$student_enrollment_id).'" target="_blank" class="btn btn-mini">'.trim($name).'</a>';
}
$data_from_array = implode('',$data_formatted);
$out .= str_replace('{day}', $day, str_replace('{content}', $data_from_array, $temp));
$data_formatted = array_fill(0,count($data_formatted), null); // line added to reset the values in previous loop
}else{
$out .= str_replace('{day}', $day, str_replace('{content}', $data[$day], $temp));
}
}
else
{
// Cells with no content
$temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_no_content_today'] : $this->temp['cal_cell_no_content'];
$out .= str_replace('{day}', $day, $temp);
}
是的,这就是我需要的,谢谢,又学了一个关键字array\u fill
再次感谢。