Php 创建<;tr>;在for循环中添加标记
我正在创建日历。所以,我在网上找到了一些东西,现在我正努力让它按照我需要的方式工作。问题是天数是以水平方式创建的 这就是它的样子: 因此,您可以看到只有Php 创建<;tr>;在for循环中添加标记,php,css,Php,Css,我正在创建日历。所以,我在网上找到了一些东西,现在我正努力让它按照我需要的方式工作。问题是天数是以水平方式创建的 这就是它的样子: 因此,您可以看到只有标记被创建 我试图为每6天添加标记,以便日历看起来像真正的日历 例如,第7天应在星期一以下,第8天应在星期二以下,以此类推 我需要帮助。谢谢 PS:如果你认为这个问题不够清楚,请在否决这个问题之前告诉我。我真的很想知道发生了什么事 代码如下: PHP: <?php class Calendar { /** * Construc
标记被创建
我试图为每6天添加
标记,以便日历看起来像真正的日历
例如,第7天应在星期一以下,第8天应在星期二以下,以此类推
我需要帮助。谢谢
PS:如果你认为这个问题不够清楚,请在否决这个问题之前告诉我。我真的很想知道发生了什么事
代码如下:
PHP:
<?php
class Calendar {
/**
* Constructor
*/
public function __construct(){
$this->naviHref = htmlentities($_SERVER['PHP_SELF']);
}
/********************* PROPERTY ********************/
private $dayLabels = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
private $currentYear=0;
private $currentMonth=0;
private $currentDay=0;
private $currentDate=null;
private $daysInMonth=0;
private $naviHref= null;
/********************* PUBLIC **********************/
/**
* print out the calendar
*/
public function show() {
$year = null;
$month = null;
if(null==$year&&isset($_GET['year'])){
$year = $_GET['year'];
}else if(null==$year){
$year = date("Y",time());
}
if(null==$month&&isset($_GET['month'])){
$month = $_GET['month'];
}else if(null==$month){
$month = date("m",time());
}
$this->currentYear=$year;
$this->currentMonth=$month;
$this->daysInMonth=$this->_daysInMonth($month,$year);
$content='<fieldset>'.
'<legend class="cyan bold">Tutors Schedule</legend>'.
//head nav '<' & '>' buttons & month
$this->_createNavi().
//end head
'<table class="table table-bordered">'.
'<thead>'.
'<tr>'.$this->_createLabels().'</tr>' .
'</thead>' .
'<tbody>'.
'<tr>';
$weeksInMonth = $this->_weeksInMonth($month,$year);
// Create weeks in a month
for( $i=0; $i<$weeksInMonth; $i++ ){
//create <tr> tags
//Create days in a week
for($j=1;$j<=7;$j++){
$content.=$this->_showDay($i*7+$j);
}
//Close </tr>
}
'</tbody>'.
'</table>';
'</fieldset>';
return $content;
}
/********************* PRIVATE **********************/
/**
* create the li element for ul
*/
private function _showDay($cellNumber){
if($this->currentDay==0){
$firstDayOfTheWeek = date('N',strtotime($this->currentYear.'-'.$this->currentMonth.'-01'));
if(intval($cellNumber) == intval($firstDayOfTheWeek)){
$this->currentDay=1;
}
}
if( ($this->currentDay!=0)&&($this->currentDay<=$this->daysInMonth) ){
$this->currentDate = date('Y-m-d',strtotime($this->currentYear.'-'.$this->currentMonth.'-'.($this->currentDay)));
$cellContent = $this->currentDay;
$this->currentDay++;
}else{
$this->currentDate =null;
$cellContent=null;
}
return '<td id="td-'.$this->currentDate.'" class=" td-top-text '.($cellNumber%7==1?' start ':($cellNumber%7==0?' end ':' ')).
($cellContent==null?'mask':'').'"><div class="inside">'.$cellContent.'</div></td>';
}
/*Event Calendar Month */
.td-top-text {
vertical-align: top;
text-align: right;
}
.inside-date, .td-top-text {
text-align: right;
}
.inside-event {
text-align: left;
}
td.td-top-text {
width:14.2857142857%; /* 100% divided by 7 */
position:relative;
height: 100%;
}
td.td-top-text:before {
content:'';
display:block;
margin-top:100%;
position: absolute;
}
td.td-top-text .inside {
font-size: 15px;
position: relative;
top:2px;
bottom:2px;
left:2px;
right:2px;
overflow-x: hidden;
}
创建一个
$count
变量,一旦它达到7,它将关闭该行并打开一个新行,并将$count
重置为0。在循环中,将$count
增加1,并让if
语句检查它是否在该循环中也达到了7。我不确定我是否完全理解了这个问题,但你知道吗
这是什么意思
for( $i=0; $i<$weeksInMonth; $i++ ){
$content .= "<tr>";
//Create days in a week
for($j=1;$j<=7;$j++){
$content.=$this->_showDay($i*7+$j);
}
$content .= "</tr>";
}
for($i=0;$iCSS示例:
php代码:
$i = 1;
$content='<fieldset><legend class="cyan bold">Tutors Schedule</legend>';
foreach($dayName as $dd) {
$content .= '<div>'.$dd.'</div>';
}
while($i <= $this->daysInMonth) {
$content .= '<div>'.$i.'</div>';
}
$content .= '</fieldset>';
1.
2.
3.
4.
5.
6.
7.
8.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
请将您的发帖限制在适用于该问题的代码上。@Dagon当然……我会尽我最大的努力……谢谢您为什么不将
和
环绕在一周中的几天循环中?@Dagon完成了。我相信问题就在这两者之间methods@blahfunk不知道你在说什么。:/你的意思是在这里添加
返回“.$cellContent.”;
该死!是的……我做错了,我是这样做的,$content=”“
所以你只是在=
之前添加了
。你能解释一个lil吗?但这是答案。”。=“在php中是一个串联。与$content=$content相同。”。如果你只是做一个“=”它将用表达式的右侧替换以前的内容。OoOOoOooOo!!哇哦,我错过了!…非常感谢!我可能会在下周提出更多有关此活动日历的问题…我希望你仍然在场并获得这些声誉=)。。。。谢谢如果我在附近,看到问题,我会尽力回答。另外还有其他方法。谢谢你,我会仔细检查这个答案…;)