Hi all,

I'm sorry my bad english. If don't understanding something, please ask. I have a problem with my calendar. Can somebody tell me why I can't mark day cell in my calendar. Do I miss something what I can't see or is my code failed? My calendar is full year view calendar and I have start day and end day textboxes, when I click send button days is go to MySql database and should mark day cell to red in calendar in same time. Days gone to MySql fine. I have a form where is datepicker.

Here is the code:

calendar.php

<?php
setlocale(LC_TIME, "fin");

$dbuser="root";
$dbpass="";
$host="localhost";

$conn=mysql_connect($host, $dbuser, $dbpass) or die(mysql_error());
if (!$conn)
  {
  die('Could not connect: ' . mysql_error());
  }



mysql_select_db("lincal", $conn);

$act = mysql_query("SELECT * FROM action") or die(mysql_error());

$actlist = array();
while($row = mysql_fetch_array($act)) {
    $start = strtotime($row['start1']);
    $end = strtotime($row['end1']);
    $actlist[] = array($start, $end);

}

$month = date('n');
$year = date('Y');
$day = date('j');

echo '<table width="90%" border="2px #009 solid; cellspacing="10" cellpadding="0" style="text-align: center">';
echo '<tr>';
echo '<th></th>';
for ($i=1;$i<=5;$i++)
          /*these are weekdays*/
   echo '<th style="width: 25px;">Ma</th><th style="width: 25px;">Ti</th><th style="width: 25px;">Ke</th><th style="width: 25px;">To</th><th style="width: 25px;">Pe</th><th style="width: 25px;" bgcolor= "#ECECFF">La</th><th style="width: 25px;" bgcolor= "#E2E2EB">Su</th>';
echo '<th style="width: 25px;">Ma</th><th>Ti</th>';


echo '<tr>';

for ($i=0; $i<12; $i++) {

    //timestamp
    $aikaleima = mktime(0,0,0,$month+$i,1,$year);
    $dayofweek = date('w', $aikaleima);
    $amountofdays = date('t', $aikaleima);


    //empties
    $tyhjia = $dayofweek-1;


    echo '<td style=\"width: 20px; text-align: center;\"">'.strftime("%B %Y", $aikaleima).'</td>';


                         //empties
    if ($dayofweek == 0) $tyhjia = 6;
    //empties
    $tyhjia--;
    for ($j=-1*$tyhjia; $j<=$amountofdays; $j++) {
    //this day
    $tamaPV = mktime(0,0,0,$month,1,$year);
        if($j == date('j') && $i == 0) {
          echo '<td bgcolor= "yellow" span style="color: red;">';

        } else {
           //act
          $tapahtuma = false;
                    //actlist
          foreach ($tapahtumalista as $tl) {     //this day //act
              if ($tl[0] <= $tamaPV && $tl[1] >= $tamaPV) $tapahtuma = true;
          }    //act
          if ($tapahtuma == true) echo '<td bgcolor="red">';
          else echo '<td>';
        }

        if ($j>0 && ($i>0 || $j>=date('j'))) echo $j;
        else echo '&nbsp';
         echo '</td>';

    }
        echo '</tr>';

}
echo '</table>';


?> 

insert.php

<?php
$dbuser="root";
$dbpass="";
$host="localhost";

$conn=mysql_connect($host, $dbuser, $dbpass) or die(mysql_error());
if (!$conn)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db('lincal', $conn);

if (isset($_POST['submit'])) {
$tunnus = $_POST['tunnus'];
$start1 = $_POST['start1'];
$end1 = $_POST['end1'];

//day
$paiva = explode('.', $start1);
$dd = $paiva[0];
$mm = $paiva[1];
$yyyy = $paiva[2];

$start1 = $yyyy.'-'.$mm.'-'.$dd;
//day
$paiva = explode('.', $end1);
$dd = $paiva[0];
$mm = $paiva[1];
$yyyy = $paiva[2];

$end1 = $yyyy.'-'.$mm.'-'.$dd;

$insert = "INSERT INTO action VALUES('$tunnus', '$start1', '$end1')";
if (!mysql_query($insert,$conn))
  {
  die('Error: ' . mysql_error());
  }
header("Location: kalenteri2.php");
}
mysql_close($conn);

?> 

Please help me, I'm newbie in php. Thanks for advance. :S

Please, help me out of this problem. If something question please ask.

-Make11

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.