2016-04-14 90 views
1

我一直在尋找各種方法來使這個日曆開始週一而不是週日。使我週日開始週一而不是週日

我一直在嘗試很多不同的事情,例如$ firstDayArray ['wday'] - 1,但事情是它會創建1個更多的空白空間,這將使日曆跳過一天。

任何形式的幫助會很好! P.s我是一個巨大的noob,但試圖練習。我一直在尋找這個偉大的網站幾乎每個角落的答案,還沒有找到它。

<?php 
define("ADAY", (60*60*24)); 
if ((!isset($_POST['month'])) || (!isset($_POST['year']))){ 
    $nowArray =getdate(); 
    $month = $nowArray['mon']; 
    $year = $nowArray['year']; 
} else { 
    $month = $_POST['month']; 
    $year = $_POST['year']; 
} 
$start = mktime (12, 0, 0, $month, 1, $year); 
$firstDayArray = getdate($start); 
?> 
<!DOCTYPE html> 

<html> 
<head> 
<title><?php echo "Calendar:".$firstDayArray['month']." 
".$firstDayArray['year']; ?> 
</title> 
<meta charset="utf-8"> 
<meta lang="da"> 
<link type="text/css" rel="stylesheet" href="calendar_style.css"> 
</head> 
<body> 
<form align="center" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 

<select name="month"> 
<?php 
$months = Array("Januar", "Februar", "Marts", "April", "Maj", "Juni", "Juli", "August", 
"September", "Oktober", "November", "December"); 
for ($x=1; $x <= count($months); $x++) { 
    echo"<option value=\"$x\""; 
    if ($x == $month) { 
     echo " selected"; 
    } 
    echo ">" .$months[$x-1]."</option>"; 
} 
?> 
</select> 
<select name="year"> 
<?php 
for ($x=2016; $x<=2018; $x++) { 
    echo "<option"; 
    if ($x == $year) { 
     echo " selected"; 
    } 
    echo ">$x</option>"; 
} 
?> 
</select> 
<button type="submit" name="submit" value="submit">Gå til måned</button> 

</form> 
<br> 

<?php 
$days = Array("Man", "Tir", "Ons", "Tor", "Fre", "Lør", "Søn"); 
echo "<table><tr>\n"; 
foreach ($days as $day) { 
    echo "<th>" .$day."</th>\n"; 
} 
for ($count=0; $count < (6*7); $count++) { 
    $dayArray = getdate($start); 
    if (($count % 7) == 0) { 
     if ($dayArray['mon'] != $month) { 
      break; 
     } else { 
      echo "</tr><tr>\n"; 
     } 
    } 
    if ($count < $firstDayArray['wday'] || $dayArray['mon'] != $month) { 
     echo "<td>&nbsp;</td>\n"; 
    } else { 
     echo "<td>" .$dayArray['mday']."</td>\n"; 
     $start += ADAY; 
    } 
} 
echo "</tr></table>"; 
?> 
</body> 
</html> 
+0

一旦設置了' display:block',你需要設置'margin:0 auto'來居中對齊這些元素 –

回答

0

您可以使用Bootstrap 3作爲輸入。 您可以禁用周的天(週六,週日) https://eonasdan.github.io/bootstrap-datetimepicker/

,因爲這

<div class="container"> 
<div class="col-sm-6" style="height:130px;"> 
    <div class="form-group"> 
     <div class='input-group date' id='datetimepicker11'> 
      <input type='text' class="form-control" /> 
      <span class="input-group-addon"> 
       <span class="glyphicon glyphicon-calendar"> 
       </span> 
      </span> 
     </div> 
    </div> 
</div> 
<script type="text/javascript"> 
    $(function() { 
     $('#datetimepicker11').datetimepicker({ 
      daysOfWeekDisabled: [0, 6] 
     }); 
    }); 
</script> 

0

嘗試以下,它的工作原理:

<?php 
$days = Array("Man", "Tir", "Ons", "Tor", "Fre", "Lør", "Søn"); 
echo "<table><tr>\n"; 
foreach ($days as $day) { 
    echo "<th>" .$day."</th>\n"; 
} 
for ($count=0; $count < (6*7); $count++) { 
    $dayArray = getdate($start); 
    if ((($count + 7) % 7) == 0) { 
     if ($dayArray['mon'] != $month) { 
      break; 
     } else { 
      echo "</tr><tr>\n"; 
     } 
    } 
    if ($count < ($firstDayArray['wday'] + 6) || $dayArray['mon'] != $month) { 
     echo "<td>&nbsp;</td>\n"; 
    } else { 
     echo "<td>" .$dayArray['mday']."</td>\n"; 
     $start += ADAY; 
    } 
} 
echo "</tr></table>"; 
?> 
相關問題