agenda legata a db

amhal

Utente Attivo
17 Feb 2011
89
1
8
Ciao a tutti, vorrei creare un'agenda legata al db, ovvero quando la apro devo poter vedere oltre ai giorni anche i possibili appuntamenti. Ho trovato questa agenda in php, ma non riesco ad adattarla al mio db, perché il codice così come è, crea un link sul giorno dell'appuntamento, io invece vorrei far apparire questo link nel riquadro del giorno stesso, inoltre, sempre se è possibile, vorrei poter mandare a video anche i riquadri dei giorni precedenti e successivi, almeno fino a pareggiare i riquadri.
Posto il codice:

PHP:
<!Doctype>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<?php

function ShowCalendar($m,$y)
{
  if ((!isset($_GET['d']))||($_GET['d'] == ""))
  {
    $m = date('n');
    $y = date('Y');
  }else{
    $m = (int)strftime( "%m" ,(int)$_GET['d']);
    $y = (int)strftime( "%Y" ,(int)$_GET['d']);
    $m = $m;
    $y = $y;
  }

  $precedente = mktime(0, 0, 0, $m -1, 1, $y);
  $successivo = mktime(0, 0, 0, $m +1, 1, $y);

  $nomi_mesi = array(
    "Gen",
    "Feb",
    "Mar",
    "Apr",
    "Mag",
    "Giu", 
    "Lug",
    "Ago",
    "Set",
    "Ott",
    "Nov",
    "Dic"
  );
  $nomi_giorni = array(
    "Lun",
    "Mar",
    "Mer",
    "Gio",
    "Ven",
    "Sab",
    "Dom"
  );

  $cols = 7;
  $days = date("t",mktime(0, 0, 0, $m, 1, $y)); 
  $lunedi= date("w",mktime(0, 0, 0, $m, 1, $y));
  if($lunedi==0) $lunedi = 7;
  echo "<table id='calendario'>\n"; 
  echo "<tr>\n
  <td class='none' colspan=\"".$cols."\">
  <a href=\"?d=" . $precedente . "\">&lt;&lt;</a>
  " . $nomi_mesi[$m-1] . " " . $y . " 
  <a href=\"?d=" . $successivo . "\">&gt;&gt;</a></td></tr>";
  foreach($nomi_giorni as $v)
  {
    echo "<td class='giorni'><b>".$v."</b></td>\n";
  }
  echo "</tr>";

  for($j = 1; $j<$days+$lunedi; $j++)
  {
    if($j%$cols+1==0)
    {
      echo "<tr>\n";
    }

    if($j<$lunedi)
    {
      echo "<td> </td>\n";
    }else{
      $day= $j-($lunedi-1);
      $data = strtotime(date($y."-".$m."-".$day));
      $oggi = strtotime(date("Y-m-d"));
      include 'config.php';
      $sql = "SELECT str_data FROM appuntamenti";
      $result = mysql_query($sql) or die (mysql_error());
      if(mysql_num_rows($result) > 0)
      {
        while($fetch = mysql_fetch_array($result))
        {
          $str_data = $fetch['str_data'];
          if ($str_data == $data)
          {
            $day = "<a href=\"appuntamenti.php?day=$str_data\">$day</a>";
			
          }
        }
      }

      if($data != $oggi)
      {
        echo "<td>".$day."</td>";
      }else{
        echo "<td><b>".$day."</b></td>";
      }
    }

    if($j%$cols==0)
    {
      echo "</tr>";
    }
  }
  echo "<tr></tr>";
  echo "</table>";
}
ShowCalendar(date("m"),date("Y")); 
?>

</body>
</html>



questo è il codice del db :

PHP:
-- MySQL dump 10.11
--
-- Host: localhost    Database: agenda
-- ------------------------------------------------------
-- Server version	5.0.77-community-nt

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `appuntamenti`
--

DROP TABLE IF EXISTS `appuntamenti`;
SET @saved_cs_client     = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `appuntamenti` (
  `id` int(11) NOT NULL auto_increment,
  `titolo` varchar(255) NOT NULL default '',
  `testo` text NOT NULL,
  `str_data` int(10) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
SET character_set_client = @saved_cs_client;

--
-- Dumping data for table `appuntamenti`
--

LOCK TABLES `appuntamenti` WRITE;
/*!40000 ALTER TABLE `appuntamenti` DISABLE KEYS */;
INSERT INTO `appuntamenti` VALUES (1,'prova1','pp',1377986400),(2,'prova appuntamento','testo appuntamento',1380924000);
/*!40000 ALTER TABLE `appuntamenti` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2013-10-04  9:02:30

grazie a tutti
 

Longo8

Utente Attivo
28 Mar 2011
1.694
0
36
Per adattare la tabella fai stampare comunque i td contenenti uno spazio.
 

amhal

Utente Attivo
17 Feb 2011
89
1
8
Grazie intanto per aver risposto, ok per completare la tab, invece un consiglio per far apparire gli appuntamenti senza avere un link sul giorno?

ciao
 

Longo8

Utente Attivo
28 Mar 2011
1.694
0
36
Devi comunque creare il calendario con i giorni ma ci sarà il link solo ai giorni dove c'è l'appuntamento.
 

amhal

Utente Attivo
17 Feb 2011
89
1
8
la teoria è chiara..è la pratica che non so fare:crying: come si fa?
 

Longo8

Utente Attivo
28 Mar 2011
1.694
0
36
Guarda ti scrivo qualcosa così al volo.
Mettiamo caso che hai un ciclo per stampare i giorni:
PHP:
foreach($giorni as $giorno){ 
  if($giorno == $myday && $mese == $mymonth && $anno == $myyear)
    echo '<a href="ciao.php?date=$giorno.$mese.$anno">$giorno</a>';
}
 

Discussioni simili