Kalender - udtræk af id
Hej derude.Jeg har et problem, for har en rigtig fin kalender. men vil dog gerne kunne udbygge den lidt. Så nede ved selve visningen af eventet ville jeg gerne kunne lave et link som sendte brugeren videre. men hvordan henter jeg id'et fra databsen, så jeg kan smide det ind i linket?
Håber der er en som kan hjælpe!
Koden ser således ud:
<?php
setlocale(LC_ALL, "da_DK");
date_default_timezone_set("Europe/Copenhagen");
header("Content-Type: text/html; charset=ISO-8859-1");
$events = array();
$mysql_hostname = "localhost";
$mysql_username = "user";
$mysql_password = "pass";
$mysql_database = "database";
$db = new mysqli($mysql_hostname, $mysql_username, $mysql_password, $mysql_database);
$month = (int)$_GET["month"];
$year = (int)$_GET["year"];
if( !checkdate($month, 1, $year) )
$start = mktime(0, 0, 0, date("n"), 1, date("Y"));
else
$start = mktime(0, 0, 0, $month, 1, $year);
$end = mktime(23, 59, 59, date("n", $start), date("t", $start), date("Y", $start));
$sql = "SELECT * FROM pCalendar WHERE DATE(pDate) >= '".date("Y-m-d", $start)."' AND DATE(pDate) <= '".date("Y-m-d", $end)."' ORDER BY pDate";
$res = $db->query($sql);
if( $res->num_rows > 0)
{
while ($obj = $res->fetch_object())
{
$timestamp = strtotime($obj->pDate);
$events[date("d", $timestamp)][] = $obj->pDescription;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>pCalendar</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<style type="text/css">
*
{
margin: 0px;
padding: 0px;
font-family: Calibri, Verdana, "Sans Serif";
font-size: 11px;
}
#pCalendar
{
width: 600px;
border: 1px solid #CECECE;
margin: 0px auto;
}
#pCalendar label
{
display: block;
color: #CECECE;
}
#pCalendar div
{
padding: 5px;
border-bottom: 1px dashed #CECECE;
}
#pCalendar div.pNavigation
{
text-align: center;
border: none;
}
a.pMonthPrev
{
float: left;
}
a.pMonthNext
{
float: right;
}
#pCalendar ul
{
list-style-type: square;
margin-left: 20px;
}
#pCalendar div.weekendDay
{
background-color: #DEDEDE;
}
</style>
</head>
<body>
<div id="pCalendar">
<div class="pNavigation">
<a class="pMonthPrev" href="?month=<?php echo date("n", ($start-3600)); ?>&year=<?php echo date("Y", ($start-3600)); ?>">Forrige</a>
<a class="pMonthNext" href="?month=<?php echo date("n", ($end+3600)); ?>&year=<?php echo date("Y", ($end+3600)); ?>">Næste</a>
<h1><?php echo ucfirst(strftime("%B", $start));?> <?php echo date("Y", $start); ?></h1>
</div>
<?php for($i = 1; $i <= date("t", $start); $i++):
$class = "";
if( date("w", mktime(0, 0, 0, date("n", $start), $i, date("Y", $start))) == 0 || date("w", mktime(0, 0, 0, date("n", $start), $i, date("Y", $start))) == 6 )
$class = "weekendDay";
?>
<div class="<?php echo $class; ?>">
<label><?php echo $i; ?>.</label>
<p>
<?php if(isset($events[$i])): ?>
<ul>
<?php foreach($events[$i] as $event): ?>
<li><?php echo $event; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</p>
</div>
<?php endfor; ?>
</div>
</body>
</html>