Avatar billede clemmesbmw Nybegynder
12. november 2002 - 16:39 Der er 11 kommentarer og
1 løsning

Fejl i kalender script

Jeg har et kalender script som jeg aldrig har fået 100% til at virke...
Problemet er, at kalenderen ikke fører noget over fra de første par uger... F.eks. skriver den ikke de første 2 søndage i advent...
Koden kommer nedenfor, håber I kan hjælpe! (der er noget input til at lave tabellerne i phpMyAdmin)

<?php
    # Pre-values
    $year = 2002;
    $month = 12;

    # Catch month or year if passed
    if (isset($HTTP_GET_VARS["month"])) $month = $HTTP_GET_VARS["month"];
    if (isset($HTTP_GET_VARS["year"])) $year = $HTTP_GET_VARS["year"];

    # Static date names - language specific
    $DAYNAME = array("Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag", "Lørdag", "Søndag");
    $MONTHNAME = array("Januar", "Februar", "Marts", "April", "Maj", "Juni", "Juli", "August", "September", "Oktober", "November", "December");

    # Fetch from DB
/*
CREATE TABLE testkalender (
  id smallint(5) unsigned NOT NULL auto_increment,
  startdate date NOT NULL default '0000-00-00',
  days tinyint(3) unsigned NOT NULL default '1',
  rooms tinyint(3) unsigned NOT NULL default '1',
  title tinytext,
  stamp timestamp(14) NOT NULL,
  PRIMARY KEY  (id)
) TYPE=MyISAM;
*/
    # DB CONNECT
    mysql_connect('xxx','xxx','xxx');
    mysql_select_db('xxx');

    $sql = mysql_query("
        SELECT id, startdate, days, rooms, title, beskrivelse
        FROM testkalender
    ");

    $ASSIGNMENT = array();
    if (mysql_num_rows($sql)) {
        while ($foo = mysql_fetch_assoc($sql)) {
            list($fy,$fm,$fd) = explode('-', $foo["startdate"]);
            for ($i=0; $i<$foo["days"]; $i++) {
                $d = $i+1;
                $ASSIGNMENT[date('Y', mktime(0,0,0,$fm,$fd+$i,$fy))][date('m', mktime(0,0,0,$fm,$fd+$i,$fy))][date('d', mktime(0,0,0,$fm,$fd+$i,$fy))][] = array(
                    "rooms"=>$foo["rooms"],
                    "beskrivelse"=>$foo["beskrivelse"],
                    "title"=>''.$foo["title"].' '.'(dag '.$d.'/'.$foo["days"].')'
                );
            }
        }
    }


    # Functions
    function date_info($info, $month, $year) {
        return date($info, mktime(0,0,0,$month,1,$year));
    }


    # Init months array with days and first day of month
    $MONTHS = array();

    # Initialize days in month
    $MONTHS["days"] = date_info("t", $month, $year);
    $MONTHS["firstday"] = date_info("w", $month, $year);
    $MONTHS["weekno"] = date_info("W", $month, $year);
    if ($MONTHS["firstday"] == 0) $MONTHS["firstday"] == 7;
    $MONTHS["firstday"]--;
?>


<center>
2002: | <a href='index.php?site=kalender&year=2002&month=8'>August</a> | <a href='index.php?site=kalender&year=2002&month=9'>September</a> | <a href='index.php?site=kalender&year=2002&month=10'>Oktober</a> | <a href='index.php?site=kalender&year=2002&month=11'>Nobember</a> | <a href='index.php?site=kalender&year=2002&month=12'>December</a> |
<a href="kalender_2003.php">-> 2003 >-></a>
</center>
<br><br>


<?php
    # Show calendar

    # Set weeknumber
    $week = $MONTHS["weekno"];
?>
<br>
<table width="350" border="0" cellspacing="0" cellpadding="0" align="center">
<tr valign="top">
<td colspan="3" class="month"><b><?php echo $MONTHNAME[$month-1]; ?> <?php echo $year; ?></b></td>
</tr>

<?php
        # Loop through each day in month
        for ($i=1;$i<=$MONTHS["days"];$i++) {
            # Fix week number
            if (($MONTHS["firstday"]+$i)%7 == 0) $week++;

            # check for assignment to show
            $assignment = "";
            $rooms = 0;
            if (is_array($ASSIGNMENT[$year][$month][$i])) {
                while (list($key, $val) = each($ASSIGNMENT[$year][$month][$i])) {
                    $assignment .= $val["title"]."\n".$val["beskrivelse"]."\n\n";
                    $rooms += $val["rooms"];
                }

                $assignment .= $rooms.' i alt';
            }

            # Set colorclass for td
            $class = "normal";
            if ((($MONTHS["firstday"]+$i)%7) == 6) $class = "red";
?>
<tr>
<td witdh="100" valign="top" class="<?php echo $class; ?>"><?php echo $i; ?>.
<?php
    # Insert week no if week is starting
    if ((($MONTHS["firstday"]+$i)%7) == 0) echo "Uge: ".$week;
?>
</td>
<td witdh="250" class="<?php echo $class; ?>"><?php echo nl2br($assignment); ?></td>
</tr>
<?php
        }
?>
Avatar billede limemedia Nybegynder
13. november 2002 - 13:21 #1
Prøv med

<?php
    # Functions
    function date_info($info, $month, $year) {
        return date($info, mktime(0,0,0,$month,1,$year));
    }
   
    function getBookings($month, $year) {
        $sql = mysql_query("
            SELECT DAYOFMONTH(startdate) AS day, days, rooms, title
            FROM testkalender
            WHERE MONTH(startdate) = '$month' && YEAR(startdate) = '$year'
            ORDER BY day ASC
        ") or die(mysql_error());

        $res = array();
        if (!mysql_num_rows($sql)) return $res;
       
        while ($foo = mysql_fetch_assoc($sql)) {
            $res[$foo['day']]['title'] .= $foo['title']."\n";
            $res[$foo['day']]['totalrooms'] = $res[$foo['day']]['totalrooms'] + $foo['rooms'];
        }

        return $res;
    }

    # Pre-values
    $year = date('Y');
    $month = date('m');
   
    # Catch month or year if passed
    if (isset($_GET["month"]) && $_GET["month"] >= 1 && $_GET["month"] <= 12) $month = $_GET["month"];
    if (isset($_GET["year"]) && $_GET["year"] > $year) $year = $_GET["year"];
   
    # Static date names - language specific
    $MONTHNAME = array("", "Januar", "Februar", "Marts", "April", "Maj", "Juni", "Juli", "August", "September", "Oktober", "November", "December");
   
    # Month for listing
    $listingmonth = date('m');
    if ($year != date('Y')) $listingmonth = 1;
   
    # Init months array with days and first day of month
    $MONTHINFO = array();
   
    # Initialize days in month
    $MONTHINFO["days"] = date_info("t", $month, $year);
    $MONTHINFO["firstday"] = date_info("w", $month, $year);
    $MONTHINFO["weekno"] = date_info("W", $month, $year);
   
    # Get room assignment
    $ASSIGNMENT = getBookings($month, $year);
?>
<div align="center"><?php echo $year; ?>: <?php for ($i=$listingmonth; $i<=12; $i++) { ?> | <a href='index.php?site=kalender&year=<?php echo $year; ?>&month=<?php echo $i; ?>'><?php echo $MONTHNAME[$i]; ?></a> <?php } ?>-&gt; <a href='index.php?site=kalender&year=<?php echo $year+1; ?>&month=1'><?php echo $year+1; ?></a> &gt;-&gt;</div>

<br><br>

<table width="350" border="0" cellspacing="0" cellpadding="0" align="center">
<tr valign="top">
<td colspan="3" class="month"><b><?php echo $MONTHNAME[$month]; ?> <?php echo $year; ?></b></td>
</tr>
<?php for ($i=1; $i<$MONTHINFO["days"]; $i++) { ?>

<tr>
<td witdh="100" valign="top" class="<?php echo $class; ?>"><?php echo $i; ?>.
<?php # Insert week no if week is starting
    if ((($MONTHINFO["firstday"]+$i)%7) == 2) echo "Uge: ".++$MONTHINFO["weekno"];
?>
</td>
<td witdh="250" class="<?php echo $class; ?>">
<?php
    if (isset($ASSIGNMENT[$i])) {
        echo nl2br($ASSIGNMENT[$i]['title'])."<br>";
        echo $ASSIGNMENT[$i]['totalrooms'] . " i alt.";
    }
?>
</td>
</tr>
<?php } ?>
</table>


istedet... Der er rettet, optimeret og omskrevet en del.

/ Lars
www.ljweb.com
Avatar billede nil.dk Nybegynder
13. november 2002 - 13:40 #2
*fnis* Lars, hvad er det Jeopardy? Skal vi gætte spørgsmålet?
Avatar billede limemedia Nybegynder
13. november 2002 - 13:43 #3
nil >> svar og spørgsmålet forsvinder... Jeg må være ret sikker på de 200 point
Avatar billede clemmesbmw Nybegynder
15. november 2002 - 16:24 #4
Lars, tak for hjælpen, den kan nu vise datoer fra de 2 første uger..
Men til gengæld tager scriptet ikke længere højde for "days" i tabellen og dermed lader en event køre i f.eks. 3 dage og viser det som "Dag 1/3", "Dag 2/3" og "Dag 3/3"..

Håber du vil hjælpe færdig, og dermed få pointene...
Avatar billede limemedia Nybegynder
15. november 2002 - 16:29 #5
hej clemme,

er paa vej i seng, men kigger paa det imorgen... ping mig evt over mail...
Avatar billede clemmesbmw Nybegynder
16. november 2002 - 11:51 #6
Lyder fint hvis du får tid til at se på det idag...
Avatar billede limemedia Nybegynder
16. november 2002 - 12:50 #7
Hvad med ...

<?php
    # Functions
    function date_info($info, $month, $year) {
        return date($info, mktime(0,0,0,$month,1,$year));
    }
   
    function getBookings($month, $year) {
        $sql = mysql_query("
            SELECT DAYOFMONTH(startdate) AS day, days, rooms, title
            FROM testkalender
            WHERE MONTH(startdate) = '$month' && YEAR(startdate) = '$year'
            ORDER BY day ASC
        ") or die(mysql_error());

        $res = array();
        if (!mysql_num_rows($sql)) return $res;
       
        while ($foo = mysql_fetch_assoc($sql)) {
            if ($foo['days'] == 1) {
                $res[$foo['day']]['title'] .= $foo['title']."\n";
                $res[$foo['day']]['totalrooms'] = $res[$foo['day']]['totalrooms'] + $foo['rooms'];
            } else {
                $today = $foo['day'];
                for($i=1; $i<=$foo['days']; $i++) {
                    $res[$today]['title'] .= $foo['title']." (".$i."/".$foo['days'].")\n";
                    $res[$today]['totalrooms'] = $res[$today]['totalrooms'] + $foo['rooms'];
                    $today++;
                }
            }
        }

        return $res;
    }

    # Pre-values
    $year = date('Y');
    $month = date('m');
   
    # Catch month or year if passed
    if (isset($_GET["month"]) && $_GET["month"] >= 1 && $_GET["month"] <= 12) $month = $_GET["month"];
    if (isset($_GET["year"]) && $_GET["year"] > $year) $year = $_GET["year"];
   
    # Static date names - language specific
    $MONTHNAME = array("", "Januar", "Februar", "Marts", "April", "Maj", "Juni", "Juli", "August", "September", "Oktober", "November", "December");
   
    # Month for listing
    $listingmonth = date('m');
    if ($year != date('Y')) $listingmonth = 1;
   
    # Init months array with days and first day of month
    $MONTHINFO = array();
   
    # Initialize days in month
    $MONTHINFO["days"] = date_info("t", $month, $year);
    $MONTHINFO["firstday"] = date_info("w", $month, $year);
    $MONTHINFO["weekno"] = date_info("W", $month, $year);
   
    # Get room assignment
    $ASSIGNMENT = getBookings($month, $year);
?>
<div align="center"><?php echo $year; ?>: <?php for ($i=$listingmonth; $i<=12; $i++) { ?> | <a href='index.php?site=kalender&year=<?php echo $year; ?>&month=<?php echo $i; ?>'><?php echo $MONTHNAME[$i]; ?></a> <?php } ?>-&gt; <a href='index.php?site=kalender&year=<?php echo $year+1; ?>&month=1'><?php echo $year+1; ?></a> &gt;-&gt;</div>

<br><br>

<table width="350" border="0" cellspacing="0" cellpadding="0" align="center">
<tr valign="top">
<td colspan="3" class="month"><b><?php echo $MONTHNAME[$month]; ?> <?php echo $year; ?></b></td>
</tr>
<?php for ($i=1; $i<$MONTHINFO["days"]; $i++) { ?>

<tr>
<td witdh="100" valign="top" class="<?php echo $class; ?>"><?php echo $i; ?>.
<?php # Insert week no if week is starting
    if ((($MONTHINFO["firstday"]+$i)%7) == 2) echo "Uge: ".++$MONTHINFO["weekno"];
?>
</td>
<td witdh="250" class="<?php echo $class; ?>">
<?php
    if (isset($ASSIGNMENT[$i])) {
        echo nl2br($ASSIGNMENT[$i]['title'])."<br>";
        echo $ASSIGNMENT[$i]['totalrooms'] . " i alt.";
    }
?>
</td>
</tr>
<?php } ?>
</table>
Avatar billede clemmesbmw Nybegynder
17. november 2002 - 23:36 #8
Yup ser straks bedre ud!
Men lige en sidste ting :]
Kan du ikke putte tabellen "beskrivelse" ind? Så den bliver trukket ud lige under "title" ?
Avatar billede limemedia Nybegynder
18. november 2002 - 12:53 #9
prøv med

<?php
    # Functions
    function date_info($info, $month, $year) {
        return date($info, mktime(0,0,0,$month,1,$year));
    }
   
    function getBookings($month, $year) {
        $sql = mysql_query("
            SELECT DAYOFMONTH(startdate) AS day, days, rooms, title, beskrivelse
            FROM testkalender
            WHERE MONTH(startdate) = '$month' && YEAR(startdate) = '$year'
            ORDER BY day ASC
        ") or die(mysql_error());

        $res = array();
        if (!mysql_num_rows($sql)) return $res;
       
        while ($foo = mysql_fetch_assoc($sql)) {
            if ($foo['days'] == 1) {
                $res[$foo['day']]['title'] .= "<b>".$foo['title']."</b>\n".$foo['beskrivelse']."\n\n";
                $res[$foo['day']]['totalrooms'] = $res[$foo['day']]['totalrooms'] + $foo['rooms'];
            } else {
                $today = $foo['day'];
                for($i=1; $i<=$foo['days']; $i++) {
                    $res[$today]['title'] .= $foo['title']." (".$i."/".$foo['days'].")\n";
                    $res[$today]['totalrooms'] = $res[$today]['totalrooms'] + $foo['rooms'];
                    $today++;
                }
            }
        }

        return $res;
    }

    # Pre-values
    $year = date('Y');
    $month = date('m');
   
    # Catch month or year if passed
    if (isset($_GET["month"]) && $_GET["month"] >= 1 && $_GET["month"] <= 12) $month = $_GET["month"];
    if (isset($_GET["year"]) && $_GET["year"] > $year) $year = $_GET["year"];
   
    # Static date names - language specific
    $MONTHNAME = array("", "Januar", "Februar", "Marts", "April", "Maj", "Juni", "Juli", "August", "September", "Oktober", "November", "December");
   
    # Month for listing
    $listingmonth = date('m');
    if ($year != date('Y')) $listingmonth = 1;
   
    # Init months array with days and first day of month
    $MONTHINFO = array();
   
    # Initialize days in month
    $MONTHINFO["days"] = date_info("t", $month, $year);
    $MONTHINFO["firstday"] = date_info("w", $month, $year);
    $MONTHINFO["weekno"] = date_info("W", $month, $year);
   
    # Get room assignment
    $ASSIGNMENT = getBookings($month, $year);
?>
<div align="center"><?php echo $year; ?>: <?php for ($i=$listingmonth; $i<=12; $i++) { ?> | <a href='index.php?site=kalender&year=<?php echo $year; ?>&month=<?php echo $i; ?>'><?php echo $MONTHNAME[$i]; ?></a> <?php } ?>-&gt; <a href='index.php?site=kalender&year=<?php echo $year+1; ?>&month=1'><?php echo $year+1; ?></a> &gt;-&gt;</div>

<br><br>

<table width="350" border="0" cellspacing="0" cellpadding="0" align="center">
<tr valign="top">
<td colspan="3" class="month"><b><?php echo $MONTHNAME[$month]; ?> <?php echo $year; ?></b></td>
</tr>
<?php for ($i=1; $i<$MONTHINFO["days"]; $i++) { ?>

<tr>
<td witdh="100" valign="top" class="<?php echo $class; ?>"><?php echo $i; ?>.
<?php # Insert week no if week is starting
    if ((($MONTHINFO["firstday"]+$i)%7) == 2) echo "Uge: ".++$MONTHINFO["weekno"];
?>
</td>
<td witdh="250" class="<?php echo $class; ?>">
<?php
    if (isset($ASSIGNMENT[$i])) {
        echo nl2br($ASSIGNMENT[$i]['title'])."<br>";
        echo $ASSIGNMENT[$i]['totalrooms'] . " i alt.";
    }
?>
</td>
</tr>
<?php } ?>
</table>
Avatar billede clemmesbmw Nybegynder
18. november 2002 - 17:40 #10
Tak for hjælpen, ser godt ud!
Avatar billede clemmesbmw Nybegynder
18. november 2002 - 22:43 #11
Jov lige 1 ting:
Den viser ikke beskrivelsen på nogle events som varer flere dage - altså viser den kun titlen der...

Hvis du retter det, har du 100% fortjent de 200 point...
Avatar billede limemedia Nybegynder
19. november 2002 - 01:42 #12
here u go

<?php
    # Functions
    function date_info($info, $month, $year) {
        return date($info, mktime(0,0,0,$month,1,$year));
    }
   
    function getBookings($month, $year) {
        $sql = mysql_query("
            SELECT DAYOFMONTH(startdate) AS day, days, rooms, title, beskrivelse
            FROM testkalender
            WHERE MONTH(startdate) = '$month' && YEAR(startdate) = '$year'
            ORDER BY day ASC
        ") or die(mysql_error());

        $res = array();
        if (!mysql_num_rows($sql)) return $res;
       
        while ($foo = mysql_fetch_assoc($sql)) {
            if ($foo['days'] == 1) {
                $res[$foo['day']]['title'] .= "<b>".$foo['title']."</b>\n".$foo['beskrivelse']."\n\n";
                $res[$foo['day']]['totalrooms'] = $res[$foo['day']]['totalrooms'] + $foo['rooms'];
            } else {
                $today = $foo['day'];
                for($i=1; $i<=$foo['days']; $i++) {
                    $res[$today]['title'] .= "<b>".$foo['title']."</b> (".$i."/".$foo['days'].")\n".$foo['beskrivelse']."\n\n";
                    $res[$today]['totalrooms'] = $res[$today]['totalrooms'] + $foo['rooms'];
                    $today++;
                }
            }
        }

        return $res;
    }

    # Pre-values
    $year = date('Y');
    $month = date('m');
   
    # Catch month or year if passed
    if (isset($_GET["month"]) && $_GET["month"] >= 1 && $_GET["month"] <= 12) $month = $_GET["month"];
    if (isset($_GET["year"]) && $_GET["year"] > $year) $year = $_GET["year"];
   
    # Static date names - language specific
    $MONTHNAME = array("", "Januar", "Februar", "Marts", "April", "Maj", "Juni", "Juli", "August", "September", "Oktober", "November", "December");
   
    # Month for listing
    $listingmonth = date('m');
    if ($year != date('Y')) $listingmonth = 1;
   
    # Init months array with days and first day of month
    $MONTHINFO = array();
   
    # Initialize days in month
    $MONTHINFO["days"] = date_info("t", $month, $year);
    $MONTHINFO["firstday"] = date_info("w", $month, $year);
    $MONTHINFO["weekno"] = date_info("W", $month, $year);
   
    # Get room assignment
    $ASSIGNMENT = getBookings($month, $year);
?>
<div align="center"><?php echo $year; ?>: <?php for ($i=$listingmonth; $i<=12; $i++) { ?> | <a href='index.php?site=kalender&year=<?php echo $year; ?>&month=<?php echo $i; ?>'><?php echo $MONTHNAME[$i]; ?></a> <?php } ?>-&gt; <a href='index.php?site=kalender&year=<?php echo $year+1; ?>&month=1'><?php echo $year+1; ?></a> &gt;-&gt;</div>

<br><br>

<table width="350" border="0" cellspacing="0" cellpadding="0" align="center">
<tr valign="top">
<td colspan="3" class="month"><b><?php echo $MONTHNAME[$month]; ?> <?php echo $year; ?></b></td>
</tr>
<?php for ($i=1; $i<$MONTHINFO["days"]; $i++) { ?>

<tr>
<td witdh="100" valign="top" class="<?php echo $class; ?>"><?php echo $i; ?>.
<?php # Insert week no if week is starting
    if ((($MONTHINFO["firstday"]+$i)%7) == 2) echo "Uge: ".++$MONTHINFO["weekno"];
?>
</td>
<td witdh="250" class="<?php echo $class; ?>">
<?php
    if (isset($ASSIGNMENT[$i])) {
        echo nl2br($ASSIGNMENT[$i]['title'])."<br>";
        echo $ASSIGNMENT[$i]['totalrooms'] . " i alt.";
    }
?>
</td>
</tr>
<?php } ?>
</table>
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester