|
 |
|
| Autor |
Nachricht |
BABA66 User [User]

Anmeldung: 28.02.07 Beiträge: 14
|
Verfasst am: 29.09.2007, 02:30 Titel: Event-Kalender PHP |
|
|
Nabend Leutz,
hab mir mal ein tutorial für einen php kalender durchgelesen und den folgenden code fabriziert bzw. modifiziert.
| Code: | <html>
<head>
<title>PHP Calendar</title>
<style type="text/css">
<!--
.table.calendar {border: 1px solid #000000; border-collapse: collapse; color: #000000; background: #FFFFFF; }
.td.today { border: 1px solid white; color: #000000; background: #EFEFEF; font-weight: bold;}
.td.monthdays {border: 1px solid #434470; color: #000000; background: #FFFFFFF; }
.td.nonmonthdays { border: 1px solid white; color: #000000; background: #EFEFEF;}
.style1 {
color: #FFFFFF;
font-weight: bold;
bgcolor: #FF3333
}
.style2 {
font-weight: bold;
bgcolor: #FF3333
}
.style3 {
font-weight: bold;
bgcolor: #00FFFF
}
-->
</style>
<body>
<?php
error_reporting('0');
ini_set('display_errors', '0');
// Gather variables from
// user input and break them
// down for usage in our script
if(!isset($_REQUEST['date'])){
$date = mktime(0,0,0,date('m'), date('d'), date('Y'));
} else {
$date = $_REQUEST['date'];
}
$day = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);
// Get the first day of the month
$month_start = mktime(0,0,0,$month, 1, $year);
// Get friendly month name
$month_names = array(1=>"Januar",
2=>"Februar",
3=>"März",
4=>"April",
5=>"Mai",
6=>"Juni",
7=>"Juli",
8=>"August",
9=>"September",
10=>"Oktober",
11=>"November",
12=>"Dezember");
$month_name = date('n', $month_start);
// Figure out which day of the week
// the month starts on.
$month_start_day = date('D', $month_start);
switch($month_start_day){
case "Mon": $offset = 0; break;
case "Tue": $offset = 1; break;
case "Wed": $offset = 2; break;
case "Thu": $offset = 3; break;
case "Fri": $offset = 4; break;
case "Sat": $offset = 5; break;
case "Sun": $offset = 6; break;
}
// determine how many days are in the last month.
if($month == 1){
$num_days_last = cal_days_in_month(0, 12, ($year -1));
} else {
$num_days_last = cal_days_in_month(0, ($month -1), $year);
}
// determine how many days are in the current month.
$num_days_current = cal_days_in_month(0, $month, $year);
// Build an array for the current days
// in the month
for($i = 1; $i <= $num_days_current; $i++){
$num_days_array[] = $i;
}
// Build an array for the number of days
// in last month
for($i = 1; $i <= $num_days_last; $i++){
$num_days_last_array[] = $i;
}
// If the $offset from the starting day of the
// week happens to be Sunday, $offset would be 0,
// so don't need an offset correction.
if($offset > 0){
$offset_correction = array_slice($num_days_last_array, -$offset, $offset);
$new_count = array_merge($offset_correction, $num_days_array);
$offset_count = count($offset_correction);
}
// The else statement is to prevent building the $offset array.
else {
$offset_count = 0;
$new_count = $num_days_array;
}
// count how many days we have with the two
// previous arrays merged together
$current_num = count($new_count);
// Since we will have 5 HTML table rows (TR)
// with 7 table data entries (TD)
// we need to fill in 35 TDs
// so, we will have to figure out
// how many days to appened to the end
// of the final array to make it 35 days.
if($current_num > 35){
$num_weeks = 6;
$outset = (42 - $current_num);
} elseif($current_num < 35){
$num_weeks = 5;
$outset = (35 - $current_num);
}
if($current_num == 35){
$num_weeks = 5;
$outset = 0;
}
// Outset Correction
for($i = 1; $i <= $outset; $i++){
$new_count[] = $i;
}
// Now let's "chunk" the $all_days array
// into weeks. Each week has 7 days
// so we will array_chunk it into 7 days.
$weeks = array_chunk($new_count, 7);
// Build Previous and Next Links
$previous_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=";
if($month == 1){
$previous_link .= mktime(0,0,0,12,$day,($year -1));
} else {
$previous_link .= mktime(0,0,0,($month -1),$day,$year);
}
$previous_link .= "\"><<<</a>";
$next_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=";
if($month == 12){
$next_link .= mktime(0,0,0,1,$day,($year + 1));
} else {
$next_link .= mktime(0,0,0,($month +1),$day,$year);
}
$next_link .= "\">>>></a>";
// Build the heading portion of the calendar table
echo "<table border=\"3\" cellpadding=\"3\" cellspacing=\"3\"
class=\"calendar\" align=\"center\" table width=\"416\" height=\"353\">\n".
"<tr>\n".
"<td colspan=\"7\" bgcolor=\"#FF3366\">\n".
"<table border=\"3\" cellpadding=\"3\" cellspacing=\"3\" table align=\"center\">\n".
"<tr>\n".
"<td colspan=\"2\" width=\"75\" align=\"left\">$previous_link</td>\n".
"<td colspan=\"3\" width=\"150\" align=\"center\"><span class=\"style1\">$month_names[$month_name] $year</span></td>\n".
"<td colspan=\"2\" width=\"75\" align=\"right\">$next_link</td>\n".
"</tr>\n".
"</table>\n".
"</td>\n".
"<tr>\n".
"<td><strong>Mo</strong></td><td><strong>Di</strong></td>
<td><strong>Mi</strong></td><td><strong>Do</strong></td>
<td><strong>Fr</strong></td><td><strong>Sa</strong></td>
<td><strong>So</strong></td>\n".
"</tr>\n";
// Now we break each key of the array
// into a week and create a new table row for each
// week with the days of that week in the table data
$i = 0;
foreach($weeks AS $week){
echo "<tr>\n";
foreach($week as $d){
if($i < $offset_count){
$day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month -1,$d,$year)."\">$d</a>";
echo "<td class=\"nonmonthdays\">$day_link</td>\n";
}
if(($i >= $offset_count) && ($i < ($num_weeks * 7) - $outset)){
$day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month,$d,$year)."\">$d</a>";
if($date == mktime(0,0,0,$month,$d,$year)){
echo "<td class=\"today\" bgcolor=\"#00FFFF\" color=\"#FF3333\">$d</td>\n";
} else {
echo "<td class=\"days\">$day_link</td>\n";
}
} elseif(($outset > 0)) {
if(($i >= ($num_weeks * 7) - $outset)){
$day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month +1,$d,$year)."\">$d</a>";
echo "<td class=\"nonmonthdays\">$day_link</td>\n";
}
}
$i++;
}
echo "</tr>\n";
}
// Close out your table and that's it!
echo '<tr><td colspan="7" class="days"> </td></tr>';
echo '</table>';
?>
</body>
</html> |
soweit bin ich auch damit zufrieden, jedoch würde ich nun gerne einige events hinzufügen. beim klick auf den jeweiligen tag, soll unterhalb des kalenders jeder event mit dem dazugehörigen banner bzw. flyer angezeigt werden. Zudem soll beim rollover über die einzelnen tage, ein kasten(kenne leider die genaue bezeichnung nicht) mit den thumbnails der flyer angezeigt werden.
Um die events hinzuzufügen möchte ich noch ein kleines cms schreiben.
Leider bin ich noch PHP neuling und habe mich auch wahrscheinlich etwas mit diesem script übernommen, jedoch habe ich angefangen es langsam zu checken, bis auf die zeilen
147 | Code: | | $weeks = array_chunk($new_count, 7); |
und 187-215 | Code: | $i = 0;
foreach($weeks AS $week){
echo "<tr>\n";
foreach($week as $d){
if($i < $offset_count){
$day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month -1,$d,$year)."\">$d</a>";
echo "<td class=\"nonmonthdays\">$day_link</td>\n";
}
if(($i >= $offset_count) && ($i < ($num_weeks * 7) - $outset)){
$day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month,$d,$year)."\">$d</a>";
if($date == mktime(0,0,0,$month,$d,$year)){
echo "<td class=\"today\" bgcolor=\"#00FFFF\" color=\"#FF3333\">$d</td>\n";
} else {
echo "<td class=\"days\">$day_link</td>\n";
}
} elseif(($outset > 0)) {
if(($i >= ($num_weeks * 7) - $outset)){
$day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month +1,$d,$year)."\">$d</a>";
echo "<td class=\"nonmonthdays\">$day_link</td>\n";
}
}
$i++;
}
echo "</tr>\n";
}
// Close out your table and that's it!
echo '<tr><td colspan="7" class="days"> </td></tr>';
echo '</table>'; | (leider ist das tutorial zum script auf englisch aber es funktioniert wenigstens).
Ich bräuchte nun einige ansätze um den oben genannten zielen näher zu kommen. Vor allem das hinzufügen von events bereitet mir sorgen, weil ich ab dem punkt schon wirklich keinen plan mehr hab wie ich es angehen soll, die event-daten irgendeinem tag zuzuordnen.
Bisher habe ich mich durch zwei php-tutorials gelesen und konnte erfolgreich ein loginscript, einen geschützten bereich, einen formmailer und mysql tabellen erstellen. Teilweise habe ich mich auch mit einem pollscript sowie diesem kalender beschäftigt.
also wie oder wo soll ich eurer meinung nach weitermachen und welche befehle kann ich benutzen?
Danke im Voraus
mfg
BABA
|
|
| Nach oben |
|
 |
benjam4 Bekannter [Mod]


Anmeldung: 17.05.06 Beiträge: 1252 Wohnort: Ostfildern ...
|
Verfasst am: 29.09.2007, 15:45 Titel: |
|
|
Zu dem "Kasten" der bei Überfahren mit der Maus erscheint, solltest du dir das hier mal anschauen:
http://www.webbe.de/index.shtml?CONTENT=script_css_tooltip;LANG=de _________________ Rechtschreibfehler sind beabsichtigt, sie dienen der Verschleiherung meiner tatsächlichen Genialität
____________________________________
Eine Signatur sie alle zu knechten
|
|
| Nach oben |
|
 |
BABA66 User [User]

Anmeldung: 28.02.07 Beiträge: 14
|
Verfasst am: 29.09.2007, 20:24 Titel: |
|
|
danke schonmal für die antwort. werde mir die seite anschauen.
nun stehe ich leider vor einem neuen problem. hab es jetzt hinbekommen, dass der kalender events anzeigt, und noch einige änderungen am code vorgenommen.
Das ganze sieht nun so aus.
| Code: |
<html>
<head>
<title>PHP Calendar</title>
<style type="text/css">
<!--
.table.calendar {border: 1px solid #000000; border-collapse: collapse; color: #000000; background: #FFFFFF; }
.td.today { border: 1px solid white; color: #000000; background: #EFEFEF; font-weight: bold;}
.td.monthdays {border: 1px solid #434470; color: #000000; background: #FFFFFFF; }
.td.nonmonthdays { border: 1px solid white; color: #000000; background: #EFEFEF;}
.style1 {
color: #FFFFFF;
font-weight: bold;
bgcolor: #FF3333
}
.style2 {
font-weight: bold;
bgcolor: #FF3333
}
-->
</style>
<body>
<?php
error_reporting('0');
ini_set('display_errors', '0');
// Gather variables from
// user input and break them
// down for usage in our script
if(!isset($_REQUEST['date'])){
$date = mktime(0,0,0,date('m'), date('d'), date('Y'));
} else {
$date = $_REQUEST['date'];
}
$day = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);
// Get the first day of the month
$month_start = mktime(0,0,0,$month, 1, $year);
// Get friendly month name
$month_names = array(1=>"Januar",
2=>"Februar",
3=>"März",
4=>"April",
5=>"Mai",
6=>"Juni",
7=>"Juli",
8=>"August",
9=>"September",
10=>"Oktober",
11=>"November",
12=>"Dezember");
$month_name = date('n', $month_start);
// Figure out which day of the week
// the month starts on.
$month_start_day = date('D', $month_start);
switch($month_start_day){
case "Mon": $offset = 0; break;
case "Tue": $offset = 1; break;
case "Wed": $offset = 2; break;
case "Thu": $offset = 3; break;
case "Fri": $offset = 4; break;
case "Sat": $offset = 5; break;
case "Sun": $offset = 6; break;
}
// determine how many days are in the last month.
if($month == 1){
$num_days_last = cal_days_in_month(0, 12, ($year -1));
} else {
$num_days_last = cal_days_in_month(0, ($month -1), $year);
}
// determine how many days are in the current month.
$num_days_current = cal_days_in_month(0, $month, $year);
// Build an array for the current days
// in the month
for($i = 1; $i <= $num_days_current; $i++){
$num_days_array[] = $i;
}
// Build an array for the number of days
// in last month
for($i = 1; $i <= $num_days_last; $i++){
$num_days_last_array[] = $i;
}
// If the $offset from the starting day of the
// week happens to be Sunday, $offset would be 0,
// so don't need an offset correction.
if($offset > 0){
$offset_correction = array_slice($num_days_last_array, -$offset, $offset);
$new_count = array_merge($offset_correction, $num_days_array);
$offset_count = count($offset_correction);
}
// The else statement is to prevent building the $offset array.
else {
$offset_count = 0;
$new_count = $num_days_array;
}
// count how many days we have with the two
// previous arrays merged together
$current_num = count($new_count);
// Since we will have 5 HTML table rows (TR)
// with 7 table data entries (TD)
// we need to fill in 35 TDs
// so, we will have to figure out
// how many days to appened to the end
// of the final array to make it 35 days.
if($current_num > 35){
$num_weeks = 6;
$outset = (42 - $current_num);
} elseif($current_num < 35){
$num_weeks = 5;
$outset = (35 - $current_num);
}
if($current_num == 35){
$num_weeks = 5;
$outset = 0;
}
// Outset Correction
for($i = 1; $i <= $outset; $i++){
$new_count[] = $i;
}
// Now let's "chunk" the $all_days array
// into weeks. Each week has 7 days
// so we will array_chunk it into 7 days.
$weeks = array_chunk($new_count, 7);
// Build Previous and Next Links
$previous_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=";
if($month == 1){
$previous_link .= mktime(0,0,0,12,$day,($year -1));
} else {
$previous_link .= mktime(0,0,0,($month -1),$day,$year);
}
$previous_link .= "\"><<<</a>";
$next_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=";
if($month == 12){
$next_link .= mktime(0,0,0,1,$day,($year + 1));
} else {
$next_link .= mktime(0,0,0,($month +1),$day,$year);
}
$next_link .= "\">>>></a>";
// Build the heading portion of the calendar table
echo "<table border=\"3\" cellpadding=\"3\" cellspacing=\"3\" class=\"calendar\" align=\"center\" table width=\"416\" height=\"353\">\n".
"<tr>\n".
"<td colspan=\"7\" bgcolor=\"#FF3366\">\n".
"<table border=\"3\" cellpadding=\"3\" cellspacing=\"3\" table align=\"center\">\n".
"<tr>\n".
"<td colspan=\"2\" width=\"75\" align=\"left\">$previous_link</td>\n".
"<td colspan=\"3\" width=\"150\" align=\"center\"><span class=\"style1\">$month_names[$month_name] $year</span></td>\n".
"<td colspan=\"2\" width=\"75\" align=\"right\">$next_link</td>\n".
"</tr>\n".
"</table>\n".
"</td>\n".
"<tr>\n".
"<td><strong>Mo</strong></td><td><strong>Di</strong></td>
<td><strong>Mi</strong></td><td><strong>Do</strong></td>
<td><strong>Fr</strong></td><td><strong>Sa</strong></td>
<td><strong>So</strong></td>\n".
"</tr>\n";
// Now we break each key of the array
// into a week and create a new table row for each
// week with the days of that week in the table data
$i = 0;
foreach($weeks AS $week){
echo "<tr>\n";
foreach($week as $d){
if($i < $offset_count){
$day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month -1,$d,$year)."\">$d</a>";
echo "<td class=\"nonmonthdays\" bgcolor=\"#CCCCCC\">$day_link</td>\n";
}
if(($i >= $offset_count) && ($i < ($num_weeks * 7) - $outset)){
$day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month,$d,$year)."\">$d</a>";
if($date == mktime(0,0,0,$month,$d,$year)){
echo "<td class=\"today\" bgcolor=\"#FF3366\">$d</td>\n";
} else {
echo "<td class=\"days\">$day_link</td>\n";
}
} elseif(($outset > 0)) {
if(($i >= ($num_weeks * 7) - $outset)){
$day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month +1,$d,$year)."\">$d</a>";
echo "<td class=\"nonmonthdays\" bgcolor=\"#CCCCCC\">$day_link</td>\n";
}
}
$i++;
}
echo "</tr>\n";
}
// Close out your table and that's it!
echo '<tr><td colspan="7" class="days"> </td></tr>';
echo '</table>';
//Display events according to date.
echo "<table cellspacing=\"0\" cellpadding=\"0\" width=\"300\" align=\"center\">";
echo "<tr><td align=\"center\">Events am $day_name, $day $month_names[$month_name] $year:</td></tr>";
//Open mySQL connection
$conn = mysql_connect("localhost", "root", "") or die("Could not connect!");
//Connect to database
mysql_select_db("test") or die("Could not select database");
//Query database
$sql = "SELECT * FROM events WHERE eventDate = FROM_UNIXTIME($date)";
$result = mysql_query($sql);
//Fecth rows according to timestamp
$num_rows = mysql_num_rows($result);
if($num_rows == 0){
echo "<tr><td align=\"center\">Für Heute sind leider Keine Events gelistet.</td></tr>";
}else{
while ($row=mysql_fetch_array($result)){
$title = $row["eventTitle"];
$desc = $row["eventDesc"];
$start = $row['eventStartTime'];
$end = $row['eventEndTime'];
$cost = $row['eventCost'];
$flyer= $row['flyer'];
echo "<tr><td><b><h2>$title</h2></b></td>";
echo "<tr><td><b>$flyer</b></td>";
echo "<tr><td>Uhrzeit: $start - $end</td></tr>";
echo "<tr><td>Eintritt: ";
if ($cost > 0){
echo "$$cost</td></tr>";
} else {
echo "Free!</td></tr>";
}
echo "<tr><td>$desc<br><br></td></tr>";
}
echo "</table>";
?>
</body>
</html>
|
funktioniert alles in allem auch. aber nun habe ich versucht, über html die daten in die mysql tabelle einzutragen, aber es klappt nicht.
hier der code für die html (wäre nett wenn mir auch jemand sagen könnte, wie ich das datum und die uhrzeiten mithilfe einer liste anstatt eines textfeldes posten kann)
| Code: |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="upload.php">
<label>Titel:
<input type="text" name="titel" />
<br />
<br />
</label>
<label>Flyer:
<input type="file" name="flyer" size="40">
</label>
<p>
<label>Datum
<input type="text" name="datum" value="jjjj-mm-tt" />
</label>
</p>
<p>
<label>Uhrzeit Beginn
<input name="uhrzeit_beginn" type="text" value=" : Uhr" size="10" />
</label>
</p>
<p>
<label>Uhrzeit Ende
<input name="uhrzeit_ende" type="text" value=" : Uhr" size="10" />
</label>
</p>
<p>
<label>Kosten:
<input type="text" name="kosten" />
</label>
€</p>
<p>
<label>Beschreibung:<br />
<textarea name="beschreibung" cols="100" rows="20"></textarea>
</label>
</p>
<input name="submit" type="submit" value="Eintragen" />
</form>
</body>
</html>
|
und hier ist der code für upload.php
| Code: |
<?php
error_reporting(E_ALL);
$conn = mysql_connect("localhost", "root", "") or die("Verbindung zum Server Fehlgeschlagen");
mysql_select_db("test") or die("Datenbank konnte nicht ausgewählt werden");
$hinzufugen = mysql_query("INSERT INTO events (eventTitle,
eventDate,eventStartTime,eventEndTime,
eventCost,eventDesc,flyer) VALUES
('".$_POST['titel']."',
'".$_POST['datum']."',
'".$_POST['uhrzeit_beginn']."',
'".$_POST['uhrzeit_ende']."',
'".$_POST['kosten']."',
'".$_POST['beschreibung']."',
'".$_POST['flyer']."'") OR die(mysql_error());
?> |
wenn ich nun versuche die daten über html auf die mysql tabelle zu posten, bekomme ich die fehlermeldung:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 10
Was mache ich falsch?
wäre es hier auch möglich, die flyer statt auf mysql in einen ordner auf dem server zu speichern und fürs jeweilige event anzeigen zu lassen?
Wie kann ich dafür sorgen, dass die uhrzeit ohne sekunden angezeigt wird?
Ich weiss es sind fragen über fragen aber google hat mir hier auch nicht weitergeholfen.
mfg
BABA66
|
|
| Nach oben |
|
 |
eforium Bekannter [Mod]


Anmeldung: 20.01.06 Beiträge: 1306 Wohnort: Irgendwo i ...
|
|
| Nach oben |
|
 |
BABA66 User [User]

Anmeldung: 28.02.07 Beiträge: 14
|
Verfasst am: 29.09.2007, 22:09 Titel: |
|
|
@eforium
ich verstehe nicht so ganz, über welche meiner fragen, der link aufschluss geben soll.
meinst du bezüglich der anzeige der Uhrzeiten oder soll mir das helfen, die uhrzeiten und das datum in die tabelle einzufügen? sry ich check das grad nicht. würdest bitte ein wenig genauer werden? Mein hauptproblem ist, dass die html und die datei upload.php nicht funktioniert und nichts in die tabellen eingetragen werden.
P.S. Danke für die schnelle antwort.
|
|
| Nach oben |
|
 |
TNDAriakas Beliebter [User]


Anmeldung: 31.07.07 Beiträge: 277 Wohnort: Bremen
|
Verfasst am: 30.09.2007, 01:23 Titel: |
|
|
| eforium hat folgendes geschrieben: | Google hätte dir sehr wohl weitergeholfen.
http://php.net/date |
Ist schon richtig. Musst dir auch mal durch lesen was da steht, ansonsten sind dokumentationen sinnlos
Mit date kannst du deine $_POST['uhrzeit_beginn'] und $POST['uhrzeit_ende'] neu formatieren.
Sicher kannst du deine flyer in einem extra verzeichnis speichern. Musst dann halt die pfad zum bild in der Datenbank speichern. _________________ So long...Ari
Error! Reality.sys is corrupt. Smash head on keyboard to restart universe.
Google ist dein Freund
|
|
| Nach oben |
|
 |
|
|
 |
|
Alle Zeiten sind GMT + 1 Stunde
|
| Seite 1 von 1 |
|  |