Jump to content

Calendar problems


Faisca78

Recommended Posts

Hi every1,

 

I've got a problem with my calendar. I'm not very good with PHP, therefore I need lots of help with this. I've got a calendar with events and weeks.

 

Mi problems are as follow:

 

1. - The calendar "freezes" in the browser after going through a few months in the past or in the future. I don't know why and/or it has to do with the events.

 

2.- When I look at an event, in any month, the calendar goes back to the current month while showing me the event, which gets very confusing.

 

3.- The week numbers (i.e. 1-52) do not show properly... at the moment, all the weeks are numbered 01, and I don't really understand why. Besides, when a week is not full (i.e. the last day of the month doesn't fall on a Sunday) the week number doesn't show.

 

4.- The months in the drop down months menu change along with the months in the top menu. I wonder if they can remain in the current month. This is not important, and it doesn't matter too much.

 

This is my calendar's code:

 

<table border=0 cellspacing=0>

<?php

include("functions.php");

$tiempo_actual = time();

$dia_solo_hoy = date("d",$tiempo_actual);

if (!$_POST && !isset($_GET["nuevo_mess"]) && !isset($_GET["nuevo_anio"])){

$mess = $_GET['mess'];

$anio = $_GET['anio'];

}elseif ($_POST) {

$mess = $_POST["nuevo_mess"];

$anio = $_POST["nuevo_anio"];

}else{

$mess = $_GET["nuevo_mess"];

$anio = $_GET["nuevo_anio"];

}

 

if($mess == "" || $anio == ""){

$anio = date("Y");

$mess = date("n");

}

$ultimo = date("t",mktime(0, 0, 0, $mess, 1, $anio));

if($mess == '12' || $mess == '1'){

if($mess == '12'){

$next = 1;

$prev = $mess -1;

$anion = $anio + 1;

$aniop = $anio;

}

if($mess == '1'){

$next = $mess + 1;

$prev = 12;

$anion = $anio;

$aniop = $anio -1;

}

}else{

$next = $mess + 1;

$prev = $mess - 1;

$aniop = $anio;

$anion = $anio;

}

echo "<table width=200 height=10 cellspacing=6 cellpadding=0.5 border=0>

<tr>

<td colspan=8 align=center class=tit>

<table width=100% cellspacing=4 cellpadding=0.5 border=0><tr>

<td style=font-size:10pt;font-weight:bold;color:white><a href='".$_SERVER['PHP_SELF']."?mess=$prev&anio=$aniop' class=prev></a></td>

<td class='title'>$mes[$mess] $anio<td>

<td align=right style=font-size:10pt;font-weight:bold;color:white><a href='".$_SERVER['PHP_SELF']. "?mess=$next&anio=$anion' class=next></a></td> </table>";

echo '<tr>

<td width=14% align=center class=altn>M</td>

<td width=14% align=center class=altn>T</td>

<td width=14% align=center class=altn>O</td>

<td width=14% align=center class=altn>T</td>

<td width=14% align=center class=altn>F</td>

<td width=14% align=center class=altn>L</td>

<td width=14% align=center class=altn>S</td>

<td width=18% align=center class=altn>Vecka</td>

</tr>';

$diaa = "1";

$diaz = cargarmatriz($ultimo,$mess,$anio);

$j = 0;

while($diaa <= $ultimo){

$dia = date("D",mktime(0,0,0,$mess,$diaa,$anio)); # retorna el dia de la semana en letras...

$fecha = date("j",mktime(0,0,0,$mess,$diaa,$anio)); #retorna el dia del mes en 01/31

$dia_semana = date("w",mktime(0,0,0,$mess,$diaa,$anio)); #retorna el dia de la semana en numero

$evento = $anio."-".$mes_num[$mess]."-".$fecha;

if($dia == "Mon"){

 

echo "</tr><tr>";

}

if($fecha == "1"){

$i=1;

while($i != $dia_semana){

echo "<td> </td>";

$i++;

}

}

if($anio == date("o") && $mes[$mess] == $mes[date("n")] && $fecha == date("j")){

if($fecha == $diaz[$j] ){

echo "<td class='tddia' align='center'><b><a href='index.php?evento=$evento' target='_self'>$fecha</a></b></td>";

$j++;

}else{

 

echo "<td class='calendario' align='center'><b>$fecha</b></td>";

}

}else{

if($fecha == $diaz[$j] ){

echo "<td class='tddia' align='center'><b><a href='index.php?evento=$evento' target='_self'>$fecha</a></b></td>";

$j++;

}else{

 

//Domingos

if ($dia_semana == 0){

echo "<td align='center' class='tddom'>$fecha</td>";

echo "<td align='center' class='week'>".strftime("%V", strtotime("$adate")). "</td>";

}else{

 

echo "<td align='center'>$fecha</td>";}

}

}

$diaa++;

}

 

echo "</tr>";

?>

</table>

 

<div id="fecha_drop">

<table>

<?

 

function formularioCalendario($mess,$anio){

 

echo '

<table width=200 align="center" cellspacing="1" cellpadding="1" border="0" class=tform>

<tr><form action="index.php? '.$_SERVER['PHP_SELF'].' " method="POST">';

echo '

<td align="center" valign="top">

<select name=nuevo_mess class="select_month">

<option value="1"';

if ($mess==1)

echo "selected";

echo'>Januari

<option value="2" ';

if ($mess==2)

echo "selected";

echo'>Februari

<option value="3" ';

if ($mess==3)

echo "selected";

echo'>Mars

<option value="4" ';

if ($mess==4)

echo "selected";

echo '>April

<option value="5" ';

if ($mess==5)

echo "selected";

echo '>Maj

<option value="6" ';

if ($mess==6)

echo "selected";

echo '>Juni

<option value="7" ';

if ($mess==7)

echo "selected";

echo '>Juli

<option value="8" ';

if ($mess==8)

echo "selected";

echo '>Augusti

<option value="9" ';

if ($mess==9)

echo "selected";

echo '>September

<option value="10" ';

if ($mess==10)

echo "selected";

echo '>Oktober

<option value="11" ';

if ($mess==11)

echo "selected";

echo '>November

<option value="12" ';

if ($mess==12)

echo "selected";

echo '>December

</select>

</td>';

echo '

<td align="center" valign="top">

<select name=nuevo_anio class="select_yr">';

 

for ($cont=2006;$cont<$anio+3;$cont++){

echo "<option value='$cont'";

if ($anio==$cont)

echo " selected";

echo ">$cont";

}

echo '

</select>

</td>';

echo '

<td colspan="1" align="center" valign="top"><input type="Submit" value="GÅ" class="button" /></td>

</table>

 

</form>';

}

 

formularioCalendario($mess,$anio);

?>

 

</table>

 

<div id="events">

<table>

<?

$evento = $_GET['evento'];

if(!isset($evento)){

$evento = date("Y-m-d");

}

$conexion = conectar();

$sql = "select * from eventos where fecha = '$evento'";

$res = query($sql);

if(mysql_num_rows($res) > 0){

while($fila = mysql_fetch_array($res)){

echo "<tr><td class='tdfecha'>".$fila['fecha']."</td></tr>

<tr><td class='tdevento'>".$fila['evento']."</td></tr>";

}

}else{

echo "<tr><td></td></tr>";

}

desconectar($conexion);

 

 

?>

</table>

 

 

And this is the website where the calendar can be previewed:

 

illumino.110mb.com

 

Following is the code for the functions.php file:

 

<?php

$datos;

$mes[1] = "Januari";

$mes[2] = "Februari";

$mes[3] = "Mars";

$mes[4] = "April";

$mes[5] = "Maj";

$mes[6] = "Juni";

$mes[7] = "Juli";

$mes[8] = "Augusti";

$mes[9] = "September";

$mes[10] = "Oktober";

$mes[11] = "November";

$mes[12] = "December";

$mes_num[1] = "01";

$mes_num[2] = "02";

$mes_num[3] = "03";

$mes_num[4] = "04";

$mes_num[5] = "05";

$mes_num[6] = "06";

$mes_num[7] = "07";

$mes_num[8] = "08";

$mes_num[9] = "09";

$mes_num[10] = "10";

$mes_num[11] = "11";

$mes_num[12] = "12";

$dias[0] = "0";

function conectar(){ //Pon los datos de conexión de tu localhost

$host = "localhost";

$usuariodb = "*******";

$pwddb = "*******";

$db = "*******";

$enlace = mysql_connect($host,$usuariodb,$pwddb);// or die("No pudo conectarse : " . mysql_error());

if (!$enlace) {

die('No conectado : ' . mysql_error());

}

$seldb = mysql_select_db($db,$enlace);

if (!$seldb) {

die ('No se puede usar eventos: ' . mysql_error());

}

return $enlace;

}

 

function desconectar($conexion){

mysql_close($conexion);

}

 

function query($sql){

$res = mysql_query($sql) or die (mysql_error());

return $res;

}

 

function buscareventos($ultimo,$mess,$anio){

$conexion = conectar();

$desde = $anio."-".$mess."-01";

$hasta = $anio."-".$mess."-".$ultimo;

$sql = "select * from eventos where fecha BETWEEN '$desde' and '$hasta'";

$res = query($sql);

if(mysql_num_rows($res) > 1){

echo "<tr><th>FECHA</th><th>EVENTO</th></tr>";

while($fila = mysql_fetch_array($res)){

echo "<tr><td class='tdfecha'>".$fila['fecha']."</td><td class='tdevento'>".$fila['evento']."</td></tr>";

}

}else{

echo "<tr><td class='tdno'>No se encuentran eventos cargado en este mes.</td></tr>";

}

desconectar($conexion);

}

 

function cargarmatriz($ultimo,$mess,$anio){

$i = 0;

$conexion = conectar();

$desde = $anio."-".$mess."-01";

$hasta = $anio."-".$mess."-".$ultimo;

// $sql = "select * from eventos where fecha BETWEEN '$desde' and '$hasta' order by fecha";

$sql = "select distinct fecha from eventos where fecha BETWEEN '$desde' and '$hasta' order by fecha";

$res = query($sql);

if(mysql_num_rows($res) > 0){

while($fila = mysql_fetch_array($res)){

$fecha = $fila['fecha'];

$dia = explode("-", $fecha);

//if($dias[$i-1] != $dia[2]){

$dias[$i] = $dia[2];

//}

$i++;

}

}else{

$dias[0] = "0";

}

desconectar($conexion);

return $dias;

}

 

 

function redireccionar($time,$url){

print "<meta http-equiv=Refresh content=\"$time ; url=$url\">";

}

 

?>

 

Thanks a lot for any help,

 

N.

Link to comment
Share on other sites

Code tags are made by highlighting your code in the textarea and hitting the button that has # on it.

 

Tab it out means to make it look like this.....(notice the code block, and the highlighting)

 

<?php
  function someFunction(){
     echo 'this line was indented for easier reading'
  } 
   
  while($x < 10){
      echo 'another indented line for easier reading...';
      echo ' look another one';
  } 


?>

Link to comment
Share on other sites

Let me try again with the tabs and the code. I re-enter my problems and thanks again for the help:)

 

I've got a problem with my calendar. I'm not very good with PHP, therefore I need lots of help with this. I've got a calendar with events and weeks.

 

Mi problems are as follow:

 

1. - The calendar "freezes" in the browser after going through a few months in the past or in the future. I don't know why and/or it has to do with the events.

 

2.- When I look at an event, in any month, the calendar goes back to the current month while showing me the event, which gets very confusing.

 

3.- The week numbers (i.e. 1-52) do not show properly... at the moment, all the weeks are numbered 01, and I don't really understand why. Besides, when a week is not full (i.e. the last day of the month doesn't fall on a Sunday) the week number doesn't show.

 

4.- The months in the drop down months menu change along with the months in the top menu. I wonder if they can remain in the current month. This is not important, and it doesn't matter too much.

 

This is my calendar's code:

 

<table border=0 cellspacing=0>
<?php
    include("functions.php");
    $tiempo_actual = time();
    $dia_solo_hoy = date("d",$tiempo_actual);

         if (!$_POST && !isset($_GET["nuevo_mess"]) &&    
            !isset($_GET["nuevo_anio"])){
            $mess = $_GET['mess'];
            $anio = $_GET['anio'];
         }elseif ($_POST) {
            $mess = $_POST["nuevo_mess"];
            $anio = $_POST["nuevo_anio"];
         }else{
            $mess = $_GET["nuevo_mess"];
            $anio = $_GET["nuevo_anio"];
         }

         if($mess == "" || $anio == ""){
            $anio = date("Y");
            $mess = date("n");
         }
            $ultimo = date("t",mktime(0, 0, 0, $mess, 1, $anio));
         
         if($mess == '12' || $mess == '1'){
         
         if($mess == '12'){
            $next = 1;
            $prev = $mess -1;
            $anion = $anio + 1;
            $aniop = $anio;
         }
       
         if($mess == '1'){
            $next = $mess + 1;
            $prev = 12;
            $anion = $anio;
            $aniop = $anio -1;
          }
         }else{
            $next = $mess + 1;
            $prev = $mess - 1;
            $aniop = $anio;
            $anion = $anio;
         }

       echo "<table width=200 height=10 cellspacing=6 cellpadding=0.5 border=0>
       <tr>
           <td colspan=8 align=center class=tit>
           <table width=100% cellspacing=4 cellpadding=0.5 border=0><tr>
       <td style=font-size:10pt;font-weight:bold;color:white><a  href='".$_SERVER['PHP_SELF']."?mess=$prev&anio=$aniop' class=prev> 
       </a></td>
       <td class='title'>$mes[$mess] $anio<td>
       <td align=right style=font-size:10pt;font-weight:bold;color:white><a href='".$_SERVER['PHP_SELF']. "?mess=$next&anio=$anion' class=next>
       </a></td> </table>";
       echo '<tr>
            <td width=14% align=center class=altn>M</td>
            <td width=14% align=center class=altn>T</td>
            <td width=14% align=center class=altn>O</td>
            <td width=14% align=center class=altn>T</td>
            <td width=14% align=center class=altn>F</td>
            <td width=14% align=center class=altn>L</td>
            <td width=14% align=center class=altn>S</td>
            <td width=18% align=center class=altn>Vecka</td>
       </tr>';

       $diaa = "1";
       $diaz = cargarmatriz($ultimo,$mess,$anio);
       $j = 0;

       while($diaa <= $ultimo){
            $dia = date("D",mktime(0,0,0,$mess,$diaa,$anio)); 
                             # return week days in letters
            $fecha = date("j",mktime(0,0,0,$mess,$diaa,$anio)); 
                             #returns the day of the month in 01/31
            $dia_semana = date("w",mktime(0,0,0,$mess,$diaa,$anio));  
                                 #returns the day of the week in numbers
            $evento = $anio."-".$mes_num[$mess]."-".$fecha;

       if($dia == "Mon"){

          echo "</tr><tr>";
       }

       if($fecha == "1"){
          $i=1;

          while($i != $dia_semana){
              echo "<td> </td>";
              $i++;
           }
       }

       if($anio == date("o") && $mes[$mess] == $mes[date("n")] && $fecha == date("j")){

        if($fecha == $diaz[$j] ){
           echo "<td class='tddia' align='center'><b><a 
                     href='index.php?evento=$evento' target='_self'>$fecha</a> 
                     </b></td>";
           $j++;
        }else{
           echo "<td class='calendario' align='center'><b>$fecha</b></td>";
        }
        }else{

         if($fecha == $diaz[$j] ){
            echo "<td class='tddia' align='center'><b><a 
                      href='index.php?evento=$evento' target='_self'>$fecha</a>
                      </b></td>";
            $j++;
         }else{

        //Sundays

              if ($dia_semana == 0){
             echo "<td align='center' class='tddom'>$fecha</td>";
             echo "<td align='center' class='week'>".strftime("%V", 
                      strtotime("$adate")). "</td>"; # returns week in the year in 
                                                                  numbers
              }else{

                   echo "<td align='center'>$fecha</td>";}
              }
         }
        $diaa++;
      }

       echo "</tr>";

?>
</table>

<div id="fecha_drop">
<table>
<?

function formularioCalendario($mess,$anio){

      echo '
         <table width=200 align="center" cellspacing="1" cellpadding="1" border="0" class=tform>
         <tr><form action="index.php? '.$_SERVER['PHP_SELF'].' " method="POST">';
      
      echo '
         <td align="center" valign="top">
         <select name=nuevo_mess class="select_month">
         
      <option value="1"';
       if ($mess==1)
          echo "selected";
          echo'>Januari

      <option value="2" ';
       if ($mess==2)
           echo "selected";
           echo'>Februari
      
      <option value="3" ';
       if ($mess==3)
           echo "selected";
           echo'>Mars
      
      <option value="4" ';
       if ($mess==4)
           echo "selected";
           echo '>April
      
      <option value="5" ';
       if ($mess==5)
           echo "selected";
           echo '>Maj
      
      <option value="6" ';
       if ($mess==6)
           echo "selected";
           echo '>Juni
      
      <option value="7" ';
       if ($mess==7)
           echo "selected";
           echo '>Juli
      
      <option value="8" ';
       if ($mess==
           echo "selected";
           echo '>Augusti
      
      <option value="9" ';
       if ($mess==9)
           echo "selected";
          echo '>September

      <option value="10" ';
       if ($mess==10)
           echo "selected";
           echo '>Oktober

      <option value="11" ';
       if ($mess==11)
           echo "selected";
           echo '>November

      <option value="12" ';
       if ($mess==12)
           echo "selected";
           echo '>December
   </select>
</td>';

       echo '
        <td align="center" valign="top">
         <select name=nuevo_anio class="select_yr">';

       for ($cont=2006;$cont<$anio+3;$cont++){
           echo "<option value='$cont'";

       if ($anio==$cont)
           echo " selected";
           echo ">$cont";
       }

       echo '
     </select>
     </td>';

      echo '

        <td colspan="1" align="center" valign="top"><input type="Submit" value="GÅ" class="button" /></td>
</table>

</form>';
     }

formularioCalendario($mess,$anio);
?>

</table>

<div id="events">
<table>
<?
$evento = $_GET['evento'];

     if(!isset($evento)){
         $evento = date("Y-m-d");
     }

$conexion = conectar();
$sql = "select * from eventos where fecha = '$evento'";
$res = query($sql);

     if(mysql_num_rows($res) > 0){

        while($fila = mysql_fetch_array($res)){
                echo "<tr><td class='tdfecha'>".$fila['fecha']."</td></tr>
                <tr><td class='tdevento'>".$fila['evento']."</td></tr>";
        }
     }else{

        echo "<tr><td></td></tr>";
     }

desconectar($conexion);

?>
</table>

 

 

And this is the website where the calendar can be previewed:

 

illumino.110mb.com

 

Following is the code for the functions.php file:

 

<?php
$datos;
$mes[1] = "Januari";
$mes[2] = "Februari";
$mes[3] = "Mars";
$mes[4] = "April";
$mes[5] = "Maj";
$mes[6] = "Juni";
$mes[7] = "Juli";
$mes[8] = "Augusti";
$mes[9] = "September";
$mes[10] = "Oktober";
$mes[11] = "November";
$mes[12] = "December";
$mes_num[1] = "01";
$mes_num[2] = "02";
$mes_num[3] = "03";
$mes_num[4] = "04";
$mes_num[5] = "05";
$mes_num[6] = "06";
$mes_num[7] = "07";
$mes_num[8] = "08";
$mes_num[9] = "09";
$mes_num[10] = "10";
$mes_num[11] = "11";
$mes_num[12] = "12";
$dias[0] = "0";

function conectar(){ //Put the data for your localhost
       $host = "localhost";
       $usuariodb = "*******";
       $pwddb = "*******";
       $db = "*******";
       $enlace = mysql_connect($host,$usuariodb,$pwddb);// or die("It 
                     couldn't connect : " . mysql_error());

       if (!$enlace) {
            die('Not connected : ' . mysql_error());
       }

$seldb = mysql_select_db($db,$enlace);

       if (!$seldb) {
           die ('No se puede usar eventos: ' . mysql_error());
       }
       
       return $enlace;

}

function desconectar($conexion){
      mysql_close($conexion);
}

function query($sql){
         $res = mysql_query($sql) or die (mysql_error());
         return $res;
}

function buscareventos($ultimo,$mess,$anio){
         $conexion = conectar();
         $desde = $anio."-".$mess."-01";
         $hasta = $anio."-".$mess."-".$ultimo;
         $sql = "select * from eventos where fecha BETWEEN '$desde' and  
         '$hasta'";
         $res = query($sql);

         if(mysql_num_rows($res) > 1){
            echo "<tr><th>FECHA</th><th>EVENTO</th></tr>";

            while($fila = mysql_fetch_array($res)){
                    echo "<tr><td class='tdfecha'>".$fila['fecha']."</td><td  
                             class='tdevento'>".$fila['evento']."</td></tr>";
            }

        }else{
           echo "<tr><td class='tdno'>There are no events this month</td>
                   </tr>";
       }

desconectar($conexion);

}

function cargarmatriz($ultimo,$mess,$anio){
        $i = 0;
        $conexion = conectar();
        $desde = $anio."-".$mess."-01";
        $hasta = $anio."-".$mess."-".$ultimo;
       // $sql = "select * from eventos where fecha BETWEEN '$desde' and  
                    '$hasta' order by fecha";
        $sql = "select distinct fecha from eventos where fecha BETWEEN   
                  '$desde' and '$hasta' order by fecha";
        $res = query($sql);

        if(mysql_num_rows($res) > 0){

           while($fila = mysql_fetch_array($res)){
                   $fecha = $fila['fecha'];
                   $dia = explode("-", $fecha);

          //if($dias[$i-1] != $dia[2]){
               $dias[$i] = $dia[2];
         //}

          $i++;
          }

        }else{
               $dias[0] = "0";
        }

       desconectar($conexion);
       return $dias;
}


function redireccionar($time,$url){
         print "<meta http-equiv=Refresh content=\"$time ; url=$url\">";
}

?>

 

Thanks a lot for any help,

 

N.

Link to comment
Share on other sites

Let me try again with the tabs and the code. I re-enter my problems and thanks again for the help:)

The time before would've been good, except my browser crashed before I was able to enter the code properly.

 

My bad and sorry for the duplicates :-[

 

I've got a problem with my calendar. I'm not very good with PHP, therefore I need lots of help with this. I've got a calendar with events and weeks.

 

Mi problems are as follow:

 

1. - The calendar "freezes" in the browser after going through a few months in the past or in the future. I don't know why and/or it has to do with the events.

 

2.- When I look at an event, in any month, the calendar goes back to the current month while showing me the event, which gets very confusing.

 

3.- The week numbers (i.e. 1-52) do not show properly... at the moment, all the weeks are numbered 01, and I don't really understand why. Besides, when a week is not full (i.e. the last day of the month doesn't fall on a Sunday) the week number doesn't show.

 

4.- The months in the drop down months menu change along with the months in the top menu. I wonder if they can remain in the current month. This is not important, and it doesn't matter too much.

 

This is my calendar's code:

 

<table border=0 cellspacing=0>
<?php
    include("functions.php");
    $tiempo_actual = time();
    $dia_solo_hoy = date("d",$tiempo_actual);

         if (!$_POST && !isset($_GET["nuevo_mess"]) &&    
            !isset($_GET["nuevo_anio"])){
            $mess = $_GET['mess'];
            $anio = $_GET['anio'];
         }elseif ($_POST) {
            $mess = $_POST["nuevo_mess"];
            $anio = $_POST["nuevo_anio"];
         }else{
            $mess = $_GET["nuevo_mess"];
            $anio = $_GET["nuevo_anio"];
         }

         if($mess == "" || $anio == ""){
            $anio = date("Y");
            $mess = date("n");
         }
            $ultimo = date("t",mktime(0, 0, 0, $mess, 1, $anio));
         
         if($mess == '12' || $mess == '1'){
         
         if($mess == '12'){
            $next = 1;
            $prev = $mess -1;
            $anion = $anio + 1;
            $aniop = $anio;
         }
       
         if($mess == '1'){
            $next = $mess + 1;
            $prev = 12;
            $anion = $anio;
            $aniop = $anio -1;
          }
         }else{
            $next = $mess + 1;
            $prev = $mess - 1;
            $aniop = $anio;
            $anion = $anio;
         }

       echo "<table width=200 height=10 cellspacing=6 cellpadding=0.5 border=0>
       <tr>
           <td colspan=8 align=center class=tit>
           <table width=100% cellspacing=4 cellpadding=0.5 border=0><tr>
       <td style=font-size:10pt;font-weight:bold;color:white><a  href='".$_SERVER['PHP_SELF']."?mess=$prev&anio=$aniop' class=prev> 
       </a></td>
       <td class='title'>$mes[$mess] $anio<td>
       <td align=right style=font-size:10pt;font-weight:bold;color:white><a href='".$_SERVER['PHP_SELF']. "?mess=$next&anio=$anion' class=next>
       </a></td> </table>";
       echo '<tr>
            <td width=14% align=center class=altn>M</td>
            <td width=14% align=center class=altn>T</td>
            <td width=14% align=center class=altn>O</td>
            <td width=14% align=center class=altn>T</td>
            <td width=14% align=center class=altn>F</td>
            <td width=14% align=center class=altn>L</td>
            <td width=14% align=center class=altn>S</td>
            <td width=18% align=center class=altn>Vecka</td>
       </tr>';

       $diaa = "1";
       $diaz = cargarmatriz($ultimo,$mess,$anio);
       $j = 0;

       while($diaa <= $ultimo){
            $dia = date("D",mktime(0,0,0,$mess,$diaa,$anio)); 
                             # return week days in letters
            $fecha = date("j",mktime(0,0,0,$mess,$diaa,$anio)); 
                             #returns the day of the month in 01/31
            $dia_semana = date("w",mktime(0,0,0,$mess,$diaa,$anio));  
                                 #returns the day of the week in numbers
            $evento = $anio."-".$mes_num[$mess]."-".$fecha;

       if($dia == "Mon"){

          echo "</tr><tr>";
       }

       if($fecha == "1"){
          $i=1;

          while($i != $dia_semana){
              echo "<td> </td>";
              $i++;
           }
       }

       if($anio == date("o") && $mes[$mess] == $mes[date("n")] && $fecha == date("j")){

        if($fecha == $diaz[$j] ){
           echo "<td class='tddia' align='center'><b><a 
                     href='index.php?evento=$evento' target='_self'>$fecha</a> 
                     </b></td>";
           $j++;
        }else{
           echo "<td class='calendario' align='center'><b>$fecha</b></td>";
        }
        }else{

         if($fecha == $diaz[$j] ){
            echo "<td class='tddia' align='center'><b><a 
                      href='index.php?evento=$evento' target='_self'>$fecha</a>
                      </b></td>";
            $j++;
         }else{

        //Sundays

              if ($dia_semana == 0){
             echo "<td align='center' class='tddom'>$fecha</td>";
             echo "<td align='center' class='week'>".strftime("%V", 
                      strtotime("$adate")). "</td>"; # returns week in the year in 
                                                                  numbers
              }else{

                   echo "<td align='center'>$fecha</td>";}
              }
         }
        $diaa++;
      }

       echo "</tr>";

?>
</table>

<div id="fecha_drop">
<table>
<?php

function formularioCalendario($mess,$anio){

      echo '
         <table width=200 align="center" cellspacing="1" cellpadding="1" border="0" class=tform>
         <tr><form action="index.php? '.$_SERVER['PHP_SELF'].' " method="POST">';
     
      echo '
         <td align="center" valign="top">
         <select name=nuevo_mess class="select_month">
         
      <option value="1"';
       if ($mess==1)
          echo "selected";
          echo'>Januari

      <option value="2" ';
       if ($mess==2)
           echo "selected";
           echo'>Februari
     
      <option value="3" ';
       if ($mess==3)
           echo "selected";
           echo'>Mars
     
      <option value="4" ';
       if ($mess==4)
           echo "selected";
           echo '>April
     
      <option value="5" ';
       if ($mess==5)
           echo "selected";
           echo '>Maj
     
      <option value="6" ';
       if ($mess==6)
           echo "selected";
           echo '>Juni
     
      <option value="7" ';
       if ($mess==7)
           echo "selected";
           echo '>Juli
     
      <option value="8" ';
       if ($mess==
           echo "selected";
           echo '>Augusti
     
      <option value="9" ';
       if ($mess==9)
           echo "selected";
          echo '>September

      <option value="10" ';
       if ($mess==10)
           echo "selected";
           echo '>Oktober

      <option value="11" ';
       if ($mess==11)
           echo "selected";
           echo '>November

      <option value="12" ';
       if ($mess==12)
           echo "selected";
           echo '>December
   </select>
</td>';

       echo '
        <td align="center" valign="top">
         <select name=nuevo_anio class="select_yr">';

       for ($cont=2006;$cont<$anio+3;$cont++){
           echo "<option value='$cont'";

       if ($anio==$cont)
           echo " selected";
           echo ">$cont";
       }

       echo '
     </select>
     </td>';

      echo '

        <td colspan="1" align="center" valign="top"><input type="Submit" value="GÅ" class="button" /></td>
</table>

</form>';
     }

formularioCalendario($mess,$anio);
?>

</table>

<div id="events">
<table>
<?php
$evento = $_GET['evento'];

     if(!isset($evento)){
         $evento = date("Y-m-d");
     }

$conexion = conectar();
$sql = "select * from eventos where fecha = '$evento'";
$res = query($sql);

     if(mysql_num_rows($res) > 0){

        while($fila = mysql_fetch_array($res)){
                echo "<tr><td class='tdfecha'>".$fila['fecha']."</td></tr>
                <tr><td class='tdevento'>".$fila['evento']."</td></tr>";
        }
     }else{

        echo "<tr><td></td></tr>";
     }

desconectar($conexion);

?>
</table>

 

And this is the website where the calendar can be previewed:

 

illumino.110mb.com

 

Following is the code for the functions.php file:

 

<?php
$datos;
$mes[1] = "Januari";
$mes[2] = "Februari";
$mes[3] = "Mars";
$mes[4] = "April";
$mes[5] = "Maj";
$mes[6] = "Juni";
$mes[7] = "Juli";
$mes[8] = "Augusti";
$mes[9] = "September";
$mes[10] = "Oktober";
$mes[11] = "November";
$mes[12] = "December";
$mes_num[1] = "01";
$mes_num[2] = "02";
$mes_num[3] = "03";
$mes_num[4] = "04";
$mes_num[5] = "05";
$mes_num[6] = "06";
$mes_num[7] = "07";
$mes_num[8] = "08";
$mes_num[9] = "09";
$mes_num[10] = "10";
$mes_num[11] = "11";
$mes_num[12] = "12";
$dias[0] = "0";

function conectar(){ //Put the data for your localhost
       $host = "localhost";
       $usuariodb = "*******";
       $pwddb = "*******";
       $db = "*******";
       $enlace = mysql_connect($host,$usuariodb,$pwddb);// or die("It 
                     couldn't connect : " . mysql_error());

       if (!$enlace) {
            die('Not connected : ' . mysql_error());
       }

$seldb = mysql_select_db($db,$enlace);

       if (!$seldb) {
           die ('No se puede usar eventos: ' . mysql_error());
       }
       
       return $enlace;

}

function desconectar($conexion){
      mysql_close($conexion);
}

function query($sql){
         $res = mysql_query($sql) or die (mysql_error());
         return $res;
}

function buscareventos($ultimo,$mess,$anio){
         $conexion = conectar();
         $desde = $anio."-".$mess."-01";
         $hasta = $anio."-".$mess."-".$ultimo;
         $sql = "select * from eventos where fecha BETWEEN '$desde' and  
         '$hasta'";
         $res = query($sql);

         if(mysql_num_rows($res) > 1){
            echo "<tr><th>FECHA</th><th>EVENTO</th></tr>";

            while($fila = mysql_fetch_array($res)){
                    echo "<tr><td class='tdfecha'>".$fila['fecha']."</td><td  
                             class='tdevento'>".$fila['evento']."</td></tr>";
            }

        }else{
           echo "<tr><td class='tdno'>There are no events this month</td>
                   </tr>";
       }

desconectar($conexion);

}

function cargarmatriz($ultimo,$mess,$anio){
        $i = 0;
        $conexion = conectar();
        $desde = $anio."-".$mess."-01";
        $hasta = $anio."-".$mess."-".$ultimo;
       // $sql = "select * from eventos where fecha BETWEEN '$desde' and  
                    '$hasta' order by fecha";
        $sql = "select distinct fecha from eventos where fecha BETWEEN   
                  '$desde' and '$hasta' order by fecha";
        $res = query($sql);

        if(mysql_num_rows($res) > 0){

           while($fila = mysql_fetch_array($res)){
                   $fecha = $fila['fecha];
                   $dia = explode("-", $fecha);

          //if($dias[$i-1] != $dia[2]){
               $dias[$i] = $dia[2];
         //}

          $i++;
          }

        }else{
               $dias[0] = "0";
        }

       desconectar($conexion);
       return $dias;
}


function redireccionar($time,$url){
         print "<meta http-equiv=Refresh content=\"$time ; url=$url\">";
}

?>

Thanks a lot for any help,

 

N.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.