|
Rank: ? (2)
Member #: 29591
|
Hello, I have used a calender from the internet, now i want to build a new function in this script. A user fill in a form and save his date, i have build up already a connection to connect with the database and get the day,month,year to check. but i cant display the right day when you got a date. in line 252 it build up a start...could somebody help me please? so the question is: how can i display the right date in the calender and make that day red Code: - <html><center>
- <style>/* Standaard CSS */
- body,td,th {
- font-family: Arial, Helvetica, sans-serif;
- font-size: 10px;
- color: #333333;
- padding: 4px;
- }
- body {
- margin-left: 0px;
- margin-top: 0px;
- margin-right: 0px;
- margin-bottom: 0px;
- }
- a:link {
- color: #006699;
- }
- a:visited {
- color: #006699;
- }
- a:hover {
- color: #FF9900;
- }
- a:active {
- color: #FF9900;
- }
- .maand_header {
- font-weight: bold;
- text-align: center;
- }
- .dag_header {
- font-style: italic;
- text-align: center;
- background-color: #EEE;
- }
- .dagen_dezemaand {
- text-align: center;
- }
- .weken_tekst {
- text-align: center;
- background-color: #EEE;
- }
- .dagen_anderemaand {
- text-align: center;
- color: #666666;
- background-color: #999999;
- }
- .dagen_vandaag {
- text-align: center;
- background-color: #3c68af;
- }
- .dagen_afspraak {
- text-align: center;
- background-color: #3c68af;
- }</style>
- <?php
- //Database gegevens
- $dbhost = 'localhost'; // database host
- $dbuser = 'root'; // database user
- $dbpass = ''; // database password
- $dbname = 'kalender'; // database name
- //connect
- $connect = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
- mysql_select_db($dbname) or die(mysql_error());
- $sql = mysql_query("Select * from opgeslagen");
- $x = 0;
- while($x < mysql_num_rows($sql)){
- $link = mysql_fetch_row($sql);
- echo "$link[2],$link[3],$link[4]";
- $x++;}
- // Names for the days of the week (currently Dutch):
- $weekday['all'] = array(1=>"ma","di","wo","do","vr","za","zo");
- // Names for the months of the year (currently Dutch):
- $maand = array(1=>"januari", 2=> "februari", 3=>"maart", 4=> "april", 5=> "mei", 6=> "juni", 7=> "juli", 8=> "augustus", 9=> "september", 10=> "oktober", 11=> "november", 12=> "december");
- // Check the user-input, is it numeric and accepted by date():
- if(($_GET['month'] > 0) && ($_GET['month'] <= 12) && ($_GET['year'] > 1902) && ($_GET['year'] < 2036)) {
- if (is_numeric($_GET['month'])) {
- $input = $_GET['month'];
- }
- if (is_numeric($_GET['year'])) {
- $yearinput = $_GET['year'];
- }
- } else {
- // If no input of false input, take the current date:
- $input = date('n');
- $yearinput = date('Y');
- }
- // The current year and month:
- $currentmonth = date('n');
- $currentyear = date('Y');
- // The timestamp from the first day of the current month:
- $timestamp['start_month'] = mktime(0,0,0,$input,1,$yearinput);
- // Number of days in current month:
- $i_days['month'] = date('t',$timestamp['start_month']);
- // Sets the first day:
- $day['start_day'] = date('j',$timestamp['start_month']);
- // Which day of the week is the first day:
- $weekday['start_day'] = date('N',$timestamp['start_month']);
- // Sets the timestamp for the last day:
- $timestamp['last_month'] = mktime(0,0,0,$input,$i_days['month'],$yearinput);
- // Sets the last day:
- $day['last_day'] = date('j',$timestamp['last_month']);
- // Which day of the week is the last day:
- $weekday['last_day'] = date('N',$timestamp['last_month']);
- // Collect all data (current month only!), from first to last day:
- $i = 1;
- while ($i <= $i_days['month']) {
- $timestamp['now'] = mktime(0,0,0,$input,$i,$yearinput);
- $weekday['now'] = date('N',$timestamp['now']);
- $day['all'][$i] = array($i,$input,$yearinput,$weekday['all'][$weekday['now']]);
- $i++;
- }
- // Collect data from previous month:
- $i = $weekday['start_day']-1;
- while ($i >= 1) {
- $i_int = 1 - $i;
- $timestamp['now'] = mktime(0,0,0,$input,$i_int,$yearinput);
- $weekday['now'] = date('N',$timestamp['now']);
- $day['now'] = date('j',$timestamp['now']);
- $month['now'] = date('n',$timestamp['now']);
- $year['now'] = date('Y',$timestamp['now']);
- $day['prev']['all'][$i] = array($day['now'],$month['now'],$year['now'],$weekday['all'][$weekday['now']]);
- $i--;
- }
- // Sort the previous month:
- @sort($day['prev']['all']);
- // Collect data from next month:
- if ($weekday['last_day'] < 7) {
- $i = 1;
- while ($i + $weekday['last_day'] <= 7) {
- $i_int = $day['last_day'] + $i;
- $timestamp['now'] = mktime(0,0,0,$input,$i_int,$yearinput);
- $weekday['now'] = date('N',$timestamp['now']);
- $day['now'] = date('j',$timestamp['now']);
- $month['now'] = date('n',$timestamp['now']);
- $year['now'] = date('Y',$timestamp['now']);
- $day['next']['all'][$i] = array($day['now'],$month['now'],$year['now'],$weekday['all'][$weekday['now']]);
- $i++;
- }
- } else {
- $day['next']['all'] == "";
- }
- // Set the links to the previous en next month:
- $prev = $input - 1;
- $yearprev = $yearinput;
- if ($input == 1) {
- $prev = 12;
- $yearprev = $yearinput - 1;
- }
- $next = $input + 1;
- $yearnext = $yearinput;
- if ($input == 12) {
- $next = 1;
- $yearnext = $yearinput + 1;
- }
- // Create a default header:
- $header = "";
- $header .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
- $header .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
- $header .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n";
- $header .= "<title>Kalender</title>\n";
- $header .= "<link href=\"default.css\" rel=\"stylesheet\" type=\"text/css\" />\n";
- $header .= "</head>\n";
- // Create the body:
- $body = "";
- $body .= "<body>\n";
- // Create the table:
- $table = "";
- $table .= "<table cellspacing=\"0\" border=\"0\">\n";
- // The tableheader:
- $table .= "<tr>\n";
- $table .= "<td class=\"maand_header\" height=\"30\" width=\"25\"><a href=\"kalender.php?month=".$prev."&year=".$yearprev."\"><</a></td>\n";
- $table .= "<td class=\"maand_header\" height=\"30\" colspan=\"6\">".ucfirst($maand[$input])." ".$yearinput."</td>\n";
- $table .= "<td class=\"maand_header\" height=\"30\" width=\"25\"><a href=\"kalender.php?month=".$next."&year=".$yearnext."\">></a></td>\n";
- $table .= "</tr>\n";
- // The days of the week:
- $table .= "<tr>\n";
- $table .= "<td class=\"dag_header\" height=\"30\" width=\"25\">Wk:</td>\n";
- $i = 1;
- while ($i <= count($weekday['all'])) {
- $table .= "<td class=\"dag_header\" height=\"30\" width=\"25\">".ucfirst($weekday['all'][$i])."</td>\n";
- $i++;
- }
- // Total days to display this month:
- $day['total_prev'] = count($day['prev']['all']);
- $day['total_all'] = count($day['all']);
- $day['total_next'] = count($day['next']['all']);
- $day['total'] = $day['total_prev'] + $day['total_all'] + $day['total_next'];
- // Create a array with the days in the correct order:
- $i = 0;
- $i_int = 0;
- while ($i_int <= $day['total_prev']) {
- $display[$i] = $day['prev']['all'][$i_int];
- $i_int++;
- $i++;
- }
- $i_int = 0;
- while ($i_int <= $day['total_all']) {
- $display[$i] = $day['all'][$i_int];
- $i_int++;
- $i++;
- }
- if ($weekday['last_day'] < 7) {
- $i_int = 0;
- while ($i_int <= $day['total_next']) {
- $display[$i] = $day['next']['all'][$i_int];
- $i_int++;
- $i++;
- }
- }
- // Display the days:
- $i = 0;
- while ($i < count($display)) {
- $i_int = 0;
- if (($display[$i][0] == "") && ($display[$i][3] == "")) {
- $timestamp['now'] = mktime(0,0,0,$display[6][1],1,$display[6][2]);
- } else {
- $timestamp['now'] = mktime(0,0,0,$display[$i][1],$display[$i][0],$display[$i][2]);
- }
- $week['now'] = date('W',$timestamp['now']);
- $table .= "<tr>\n";
- $table .= "<td class=\"weken_tekst\" height=\"30\" width=\"25\">".$week['now']."</td>\n";
- while ($i_int < 7) {
- if (is_array($display[$i])) {
- if ($display[$i][1] == $input) {
- $style = "dagen_dezemaand";
- } else {
- $style = "dagen_anderemaand";
- }
- if (($display[$i][0] == date('j')) && ($display[$i][1] == date('m')) && ($yearinput == $currentyear)) {
- $style = "dagen_vandaag";
- }
- $table .= "<td class=\"".$style."\" height=\"30\" width=\"25\">".$display[$i][0]."</td>\n";
- $i_int++;
- }
- $i++;
- }
- while ($i_int < 7) {
- if (is_array($display[$i])) {
- if (($display[$i][0] == $link[2]) && ($currentmonth == $link[3]) && ($yearinput == $link[4])) {
- $style = "dagen_afspraak";
- }
- $table .= "<td class=\"".$style."\" height=\"30\" width=\"25\">".$display[$i][0]."</td>\n";
- $i_int++;
- }
- $i++;
- }
- $table .= "</tr>\n";
- }
- // The tablefooter:
- $table .= "<tr>\n";
- $table .= "<td class=\"maand_header\" height=\"30\" width=\"25\"> </td>\n";
- $table .= "<td class=\"maand_header\" height=\"30\" colspan=\"6\"><a href=\"kalender.php?month=".$currentmonth."&year=".$currentyear."\">naar huidige maand</a></td>\n";
- $table .= "<td class=\"maand_header\" height=\"30\" width=\"25\"> </td>\n";
- $table .= "</tr>\n";
- $table .= "</table>\n";
- $body .= $table;
- $body .= "</body>\n";
- // Create a default footer:
- $footer = "";
- $footer .= "</html>\n";
- // Display the header, body and footer:
- echo $header;
- echo $body;
- echo $footer;
- ?> </center></html>
|
|
Rank: ? (767)
Member #: 11085
|
Well, I can tell you why lines 252-259 are not running without to much deciphering, but in all honesty, not to be rude, you really ought to clean up your code. A problem such as this could and should be done in no more than about fifty lines, whereas you are using well over one hundred. Remove all redundancy and reduce code where less is needed. Also, your style could use a bit of work. Whatever style you happen to choose, stick to it and remain consistent, and above all, make sure your code is easily readable via descriptive, yet short, variable names. You know your are coding well when you can still understand your code easily after six months of absence. Comments on code aside, your problem is that the while loop on line 252 only runs while the variable $i_int is less than seven, meanwhile, the while loop directly above line 252 runs while the variable $i_int is less than seven. This means that by line 252, $i_int must at least be seven, therefore, lines 252-259 will not run. The solution is to simply set it to zero before the next while loop.
|