• User Attivo

    Problemi nella creazione di un calendario con php

    Salve,

    ho intenzione di creare con php un calendario nel formato come quello di mkportal.

    Ho scritto sufficiente codice php ma non visualizza niente:

    [PHP]<?php
    class cal {

    function __construct() {

    }

    function mkg($d) {
    return(date('w', mktime(0, 0, 0, $this->dati['mese'], $d, $this->dati['anno'])));
    }

    function calendario() {
    $this->dati = array(giorno => date('j'), bis => date('L'), mese => date('n'), gmese => date('t'), gsett => date('w'), setta => date('W'), anno => date('Y'), settm => round(date('t')/7)+1, gsett1 => date('w', mktime(0, 0, 0, date('n'), 1, date('Y'))));
    $this->j = 0;

    switch($this->dati['mese']) {
    case 1: $this->mese = "Gennaio"; break;
    case 2: $this->mese = "Febbraio"; break;
    case 3: $this->mese = "Marzo"; break;
    case 4: $this->mese = "Aprile"; break;
    case 5: $this->mese = "Maggio"; break;
    case 6: $this->mese = "Giugno"; break;
    case 7: $this->mese = "Luglio"; break;
    case 8: $this->mese = "Agosto"; break;
    case 9: $this->mese = "Settembre"; break;
    case 10: $this->mese = "Ottobre"; break;
    case 11: $this->mese = "Novembre"; break;
    case 12: $this->mese = "Dicembre"; break;
    default: $this->mese = ""; break;
    }

    switch($this->dati['gsett']) {
    case 0: $this->gsett = "Domenica"; break;
    case 1: $this->gsett = "Lunedì"; break;
    case 2: $this->gsett = "Martedì"; break;
    case 3: $this->gsett = "Mercoledì"; break;
    case 4: $this->gsett = "Giovedì"; break;
    case 5: $this->gsett = "Venerdì"; break;
    case 6: $this->gsett = "Sabato"; break;
    default: $this->gsett = ""; break;
    }

    echo '<table border="0" width="30%" height="30%">
    <tr>
    <td width="100%" height="15%">'.$this->mese.' '.$this->dati['anno'].'</td>
    </tr>';
    for($this->i=0; $this->i<$this->dati['settm']; $this->i++) {
    $this->k = 0;
    echo '<tr>
    <td width="14%" height="15%">';
    if($this->j == 0) {
    if($this->mkg($this->j+1) == 0) {
    echo(++$this->j == $this->dati['giorno'] ? '('.$this->j.')' : $this->j);
    }
    }
    else {
    echo(++$this->j == $this->dati['giorno'] ? '('.$this->j.')' : $this->j);
    }
    if($this->j == 0) {
    if($this->mkg($this->j+1) == 0) {
    echo(++$this->j == $this->dati['giorno'] ? '('.$this->j.')' : $this->j);
    }
    }
    else {
    echo(++$this->j == $this->dati['giorno'] ? '('.$this->j.')' : $this->j);
    }
    if($this->j == 0) {
    if($this->mkg($this->j+1) == 0) {
    echo(++$this->j == $this->dati['giorno'] ? '('.$this->j.')' : $this->j);
    }
    }
    else {
    echo(++$this->j == $this->dati['giorno'] ? '('.$this->j.')' : $this->j);
    }
    if($this->j == 0) {
    if($this->mkg($this->j+1) == 0) {
    echo(++$this->j == $this->dati['giorno'] ? '('.$this->j.')' : $this->j);
    }
    }
    else {
    echo(++$this->j == $this->dati['giorno'] ? '('.$this->j.')' : $this->j);
    }
    if($this->j == 0) {
    if($this->mkg($this->j+1) == 0) {
    echo(++$this->j == $this->dati['giorno'] ? '('.$this->j.')' : $this->j);
    }
    }
    else {
    echo(++$this->j == $this->dati['giorno'] ? '('.$this->j.')' : $this->j);
    }
    if($this->j == 0) {
    if($this->mkg($this->j+1) == 0) {
    echo(++$this->j == $this->dati['giorno'] ? '('.$this->j.')' : $this->j);
    }
    }
    else {
    echo(++$this->j == $this->dati['giorno'] ? '('.$this->j.')' : $this->j);
    }
    if($this->j == 0) {
    if($this->mkg($this->j+1) == 0) {
    echo(++$this->j == $this->dati['giorno'] ? '('.$this->j.')' : $this->j);
    }
    }
    else {
    echo(++$this->j == $this->dati['giorno'] ? '('.$this->j.')' : $this->j);
    }
    echo '</td>
    </tr>';
    }
    echo '</table>';
    }

    }

    $cal = new cal();
    $cal->calendario();
    ?>[/PHP]

    Ho voluto mettere anche il giorno di oggi tra parentesi per evidenziarlo, ma poi sistemerò io...

    Il problema è che non dà nessun errore ma come codice html restituisce questo:

    [HTML]<table border="0" width="30%" height="30%">
    <tr>
    <td width="100%" height="15%">Ottobre 2008</td>
    </tr><tr>
    <td width="14%" height="15%"></td>
    </tr><tr>
    <td width="14%" height="15%"></td>
    </tr><tr>
    <td width="14%" height="15%"></td>
    </tr><tr>
    <td width="14%" height="15%"></td>
    </tr><tr>
    <td width="14%" height="15%"></td>
    </tr></table>[/HTML]

    Mi sapete gentilmente correggereil codice php per fare venire un calendario decente?

    Grazie,
    :gthi:


  • User Attivo

    Meh? Nessuno? Perché non mi aiutate? Su avanti...

    Grazie


  • User Attivo

    potresti provare a cambiare questo
    [PHP]if($this->mkg($this->j+1) == 0)[/PHP]
    in questo
    [PHP]if($this->mkg(($this->j)+1) == 0)[/PHP]

    probabilmente le parentesi non rendono l'effetto voluto...


  • User Attivo

    Non succede niente di nuovo, è sempre come prima... come risolvo?