Faisca78 Posted December 13, 2008 Share Posted December 13, 2008 Hi, I posted a topic a few weeks ago because I have problems with my calendar script. I still haven't been able to solve it, so I was hoping somebody with more experience could help me out. These are the problems I'm experiencing: 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. Quote Link to comment Share on other sites More sharing options...
chronister Posted December 13, 2008 Share Posted December 13, 2008 Unfortunately, your probably going to have a difficult time getting help as your code is in spanish. I don't know spanish, so it would make it very difficult to decipher what is going on. But hopefully someone here knows spanish and can help you. I see the whole browser crash/lockup when you go a couple months in the future. That seems to me like a loop that does not terminate properly. My browser (firefox) was eating up over a hundred megs of memory when I killed it in task manager. I would look for a never ending loop on that aspect. There is an error here... don't know if it is just a typo on here or in your actual code.. It should be <?php $enlace = mysql_connect($host,$usuariodb,$pwddb) or die("It couldn't connect : " . mysql_error()); if (!$enlace) { die('Not connected : ' . mysql_error()); } ?> Notice the code coloring... code coloring can alert you to syntax errors very quickly. Quote Link to comment Share on other sites More sharing options...
corbin Posted December 13, 2008 Share Posted December 13, 2008 "Unfortunately, your probably going to have a difficult time getting help as your code is in spanish. I don't know spanish, so it would make it very difficult to decipher what is going on. But hopefully someone here knows spanish and can help you." I know a decent amount of Spanish, and those month names are not Spanish. Hrmmm not Italian either.... I know Mars is March in Latin, but the rest aren't Latin.... Not French either. Oh.... Just figured it out. Swedish. Quote Link to comment Share on other sites More sharing options...
chronister Posted December 13, 2008 Share Posted December 13, 2008 I wasn't even real sure it was spanish, I *thought* it was, but now that you mention it the EXTREMELY little I know of spanish, the month names are not spanish. Oops, either way I don't know that language, and as such have offered the only help I can give. Nate Quote Link to comment Share on other sites More sharing options...
Faisca78 Posted December 13, 2008 Author Share Posted December 13, 2008 Thanks everyone! I will try and translate it into English... and you are absolutely right, Spanish and Swedish;) Thanks so much for the help, N. Quote Link to comment Share on other sites More sharing options...
corbin Posted December 13, 2008 Share Posted December 13, 2008 Oh, Spanish and Swedish. I just assumed it was Swedish from the month names, but yeah, mes, día, fecha, semana.... Spanish. Dunno how I missed that. lol. Edit: Oh, by the way, when ever the page freezes, it's because your script is putting out <td>&nbps</td over and over again, so look for a possible infinite loop somewhere. Quote Link to comment Share on other sites More sharing options...
chronister Posted December 13, 2008 Share Posted December 13, 2008 Ok, good.... now I don't feel like a dumbass. I thought I saw some spanish in there... but was not sure as I can count in spanish, I know/knew the days of the week, months of the year, and can really cuss someone out with 1 phrase. Thats the extent of my spanish. Nate Quote Link to comment Share on other sites More sharing options...
Faisca78 Posted December 14, 2008 Author Share Posted December 14, 2008 Thanks Corbin, I'll try to find that loop. I would've never guessed that myself;) N. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.