mySQL データベースに接続するための calendarscript を取得しようとしています。スクリプトは、イベントを表示できるようにデータベースに接続しようとしている単純なカレンダー ピッカー ウィッチです。データベースにあるイベントをその月のすべての日に表示することができましたが、設定された日のみのリンクとして表示したいと考えています。イベントの追加や削除の機能もつけたいところですが、先に。
私のデータベースは次のようになります。
database: calendar
table: calendar_events
row1: event_title
row2: event_shortdesc
row3: event_start
これはスクリプトのコード全体です。カレンダー関数は正常に動作します。
<?php include("includes/header.php")?>
<?php require_once("includes/db_connection.php")?>
<?php include("includes/functions.php")?>
<?php
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("m");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0) {
$prev_month = 12;
$prev_year = $cYear-1;
}
if ($next_month == 13) {
$next_month = 1;
$next_year = $cYear+1;
}
$monthNames = Array("Januar", "Februar", "Mars", "April", "Mai", "Juni", "Juli",
"August", "September", "Oktober", "November", "Desember");
?>
<div id="kalendercontainer">
<a id="prev" href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>">Previous</a>
<span id="monthname"><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></span>
<a id="next" href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>">Next</a>
<table id="kalender">
<tr>
<td><strong>Man</strong></td>
<td><strong>Tir</strong></td>
<td><strong>Ons</strong></td>
<td><strong>Tor</strong></td>
<td><strong>Fre</strong></td>
<td><strong>Lør</strong></td>
<td><strong>Søn</strong></td>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday']-1;
//Get calendar events
$get_cal_events = mysql_query("SELECT * FROM calendar_events WHERE event_start = '{$startday}'");
$rows = mysql_fetch_array($get_cal_events);
$event = $rows['event_title'] . $rows['event_shortdesc'];
//Draw calendar
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ) echo "<tr>";
if($i < $startday) echo "<td></td>";
else
echo "<td>" . ($event) . ($i - $startday + 1) . "</td>";
if(($i % 7) == 6 ) echo "</tr>";
}
?>
</table>
<p></p>
</div>
<?php require("includes/footer.php")?>