Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/01/2006, 17:41
Nateskin
 
Fecha de Ingreso: junio-2002
Mensajes: 321
Antigüedad: 21 años, 10 meses
Puntos: 3
calendario (sistema americano/ingles a español)

hola chicos!! bueno viendo la pagina de macromedia devep. me encontre un ejemplo de como hacer un blog.

este blog tiene un calendario y os expongo exactamente cual es el codigo del calendario:

Archivo: connBlog (se ubica en la carpeta Connections):
Código PHP:
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connBlog "remus.iakt.ro";
$database_connBlog "mza_blog";
$username_connBlog "root";
$password_connBlog "insfarsit";
$connBlog mysql_pconnect($hostname_connBlog$username_connBlog$password_connBlog) or trigger_error(mysql_error(),E_USER_ERROR); 
?>
esto configurarlo como vuestro servidor

Código PHP:
<?php require_once('Connections/connBlog.php'); ?>
<?php
mysql_select_db
($database_connBlog$connBlog);
$query_rsArticleDates "SELECT date_format(date_art, '%Y-%c-%e') as ArticleDate FROM blg_article_art";
$rsArticleDates mysql_query($query_rsArticleDates$connBlog) or die(mysql_error());
$row_rsArticleDates mysql_fetch_assoc($rsArticleDates);
$totalRows_rsArticleDates mysql_num_rows($rsArticleDates);

?>

        <?php 
            
function build_calendar($month,$year,$day) {
                
/* Declaring the variables */
                
$daysOfWeek = array('D','L','M','M','J','V','S');
                
$firstDayOfMonth mktime(0,0,0,$month,1,$year);
                
$noDays date('t',$firstDayOfMonth);
                
$dateComponents getdate($firstDayOfMonth);
                
$dayOfWeek $dateComponents['wday'];
                
$monthName date('F',mktime(0,0,0,$month,1,$year));
                
                global 
$rsArticleDates;
                global 
$_GET;
                
                if (
mysql_num_rows($rsArticleDates) > 0){
                    
mysql_data_seek($rsArticleDates,0);
                    while(
$row_rsArticleDates mysql_fetch_assoc($rsArticleDates)){
                        
$dates[] = $row_rsArticleDates['ArticleDate'];
                    }
                }
    
                
/* Computing the previous month. */
                
if($month == 1) {
                     
$mn=12;
                     
$yn=$year-1;
                 } else {
                         
$mn=$month-1;
                         
$yn=$year;
                }
                
                
/* Computing the next month. */
                
if($month == 12) {
                    
$mn2=1;
                    
$yn2=$year+1;
                } else {
                    
$mn2=$month+1;
                    
$yn2=$year;
                }
                
                
/* Calendar header: next and previous month links */
                
$calendar "<table>";
                
$calendar .= "<tr><td><a href=index.php?m=$mn&y=$yn&d=$day>&lt;</a></td>";
                
$calendar .="<td colspan=5 align=center>$monthName, $year</td>";
                
$calendar .="<td><a href=index.php?m=$mn2&y=$yn2&d=$day>&gt;</a></td></tr>";
                
$calendar .="<tr>";         
                
                
/* Calendar header: Display the days of the week */
                
foreach($daysOfWeek as $day) { 
                      
$calendar .= "<td>$day</td>"
                } 
                
$calendar .= "</tr>"
                
$calendar .= "<tr>"

              
$currentDay 1;
             

              
/* Fill in the beginning of the calendar    body */    
              
if ($dayOfWeek 0) {  
                 
$calendar .= "<td  colspan='$dayOfWeek'>&nbsp;</td>";  
              } 
            
              
/* Generate the calendar body */        
              
while ($currentDay <= $noDays) { 
                    if (
$dayOfWeek == 7) { 
                       
$dayOfWeek 0
                       
$calendar .= "</tr><tr>"
                    } 
                    
$date $year."-".$month."-".$currentDay;
                    if (
in_array($date,$dates)) { 
                        
$calendar .= "<td><a href='index.php?m=$month&y=$year&d=$currentDay'>$currentDay</a></td>"
                    } else {
                        
$calendar .= "<td>$currentDay</td>";
                    }
                   
$currentDay++; 
                   
$dayOfWeek++; 
              } 

            
/* Filling in the end of the calendar body */
            
if ($dayOfWeek != 7) {  
                  
$remainingDays $dayOfWeek
                  
$calendar .= "<td colspan='$remainingDays'>&nbsp;</td>";  
            } 
  
              
$calendar .= "</table>"
            return 
$calendar;

if (isset(
$_GET['m']) && isset($_GET['y']) && isset($_GET['d'])){     
    
$month $_GET['m'];
    
$year $_GET['y'];
    
$day $_GET['d'];
} else {
    
$dateComponents getdate();
    
$month $dateComponents['mon'];
    
$year $dateComponents['year'];
    
$day $dateComponents['mday'];
}

echo 
build_calendar($month,$year,$day);

        
?>
        <?php
mysql_free_result
($rsArticleDates);
?>
y la base de datos:
Código PHP:
-- phpMyAdmin SQL Dump
-- version 2.6.4-pl3
-- http://www.phpmyadmin.net
-- 
-- 
Servidorlocalhost
-- Tiempo de generación06-01-2006 a las 00:36:01
-- Versión del servidor5.0.15
-- Versión de PHP5.0.5
-- 
-- 
Base de datos: `bands`
-- 

-- --------------------------------------------------------

-- 
-- 
Estructura de tabla para la tabla `blg_article_art`
-- 

CREATE TABLE `blg_article_art` (
  `
id_artint(11NOT NULL auto_increment,
  `
idtop_artint(11NOT NULL default '0',
  `
title_artvarchar(100NOT NULL default '',
  `
description_artvarchar(255NOT NULL default '',
  `
text_artlongtext NOT NULL,
  `
date_artdatetime default NULL,
  
PRIMARY KEY  (`id_art`)
ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=;

-- 
-- 
Volcar la base de datos para la tabla `blg_article_art`
-- 

INSERT INTO `blg_article_artVALUES (10'''''''2006-01-10 22:49:38'); 
viene con un ejemplo simple, tampoco me he explayado metiendo contenido pues como es para ver el ejemplo...

bueno siguiendo esto, sabeis que los americanos o ingleses empiezan la semana desde el domingo y el dia se retrasa arriba al calendario pero aki es diferente.. le he dado vueltas a esto y no he tenido narices de hacerlo bien.

hice el siguiente cambio:

Código PHP:
$firstDayOfMonth mktime(0,0,0,$month,1,$year); 
y lo cambie por:

Código PHP:
$firstDayOfMonth mktime(0,-1,0,$month,1,$year); 
y

Código PHP:
$daysOfWeek = array('D','L','M','M','J','V','S'); 
por:

Código PHP:
$daysOfWeek = array('L','M','M','J','V','S','D'); 

asi el calendario si funciona, peeeeeeeeeero al llegar al mes de abril, acaba el mes en 31 (lunes), pero al pasar al mes de mayo empieza tb la semana en 1 (lunes) y esto no me cuadra.

donde falla esto??

un saludo.