Jump to content

Agendamento/Calendario Erro


bonucci
 Share

Recommended Posts

Boas pessoal, ando com um erro no meu agendamento, o seguinte erro que se dá é este:

Notice: Undefined offset: 16 in C:\wamp\www\sibd06\agendamento.php  on line 37

A linha 37 é este:

$events[intval($row_event->day)] .= '<li><span class="title">'.stripslashes($row_event->eventTitle).'</span><span class="desc">'.stripslashes($row_event->eventContent).'</span></li>';
}			

Mas não vejo o problema, aqui deixo o código, agradecia a ajuda:

<?php
//Database connection details
$host = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_db = "sibd06";

//make connection with mysql and select the database
$mysql_connect = mysql_connect($host, $mysql_user, $mysql_password);
$db_select = mysql_select_db($mysql_db);

//check if time is set in the URL
if(isset($_GET['time']))
$time = $_GET['time'];
else
$time = time();


$today = date("Y/n/j", time());

$current_month = date("n", $time);

$current_year = date("Y", $time);

$current_month_text = date("F Y", $time);

$total_days_of_current_month = date("t", $time);

$events = array();

//query the database for events between the first date of the month and the last of date of month
$result = mysql_query("SELECT DATE_FORMAT(eventDate,'%d') AS day,eventContent,eventTitle FROM agendamento WHERE eventDate BETWEEN  '$current_year/$current_month/01' AND '$current_year/$current_month/$total_days_of_current_month'");

while($row_event = mysql_fetch_object($result))
{
//loading the $events array with evenTitle and eventContent inside the <span> and <li>. We will add then inside <ul> in the calender
$events[intval($row_event->day)] .= '<li><span class="title">'.stripslashes($row_event->eventTitle).'</span><span class="desc">'.stripslashes($row_event->eventContent).'</span></li>';
}							

$first_day_of_month = mktime(0,0,0,$current_month,1,$current_year);

//geting Numeric representation of the day of the week for first day of the month. 0 (for Sunday) through 6 (for Saturday).
$first_w_of_month = date("w", $first_day_of_month);

//how many rows will be in the calendar to show the dates
$total_rows = ceil(($total_days_of_current_month + $first_w_of_month)/7);

//trick to show empty cell in the first row if the month doesn't start from Sunday
$day = -$first_w_of_month;


$next_month = mktime(0,0,0,$current_month+1,1,$current_year);
$next_month_text = date("F \'y", $next_month);

$previous_month = mktime(0,0,0,$current_month-1,1,$current_year);
$previous_month_text = date("F \'y", $previous_month);

$next_year = mktime(0,0,0,$current_month,1,$current_year+1);
$next_year_text = date("F \'y", $next_year);

$previous_year = mktime(0,0,0,$current_month,1,$current_year-1);
$previous_year_text = date("F \'y", $previous_year);
?>

<html>
<head>
<title><?=$current_month_text?></title>
<link rel="stylesheet" href="css/master.css" type="text/css" media="screen" charset="utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script src="js/coda.js" type="text/javascript"> </script>
</head>
<body>
<h2><?=$current_month_text?></h2>
<table cellspacing="0">
	<thead>
	<tr>
		<th>Dom</th>
		<th>Seg</th>
		<th>Ter</th>
		<th>Qua</th>
		<th>Qui</th>
		<th>Sex</th>
		<th>Sab</th>
	</tr>
	</thead>
	<tr>
		<?php
		for($i=0; $i< $total_rows; $i++)
		{
			for($j=0; $j<7;$j++)
			{
				$day++;					

				if($day>0 && $day<=$total_days_of_current_month)
				{
					//YYYY-MM-DD date format
					$date_form = "$current_year/$current_month/$day";

					echo '<td';

					//check if the date is today
					if($date_form == $today)
					{
						echo ' class="today"';
					}

					//check if any event stored for the date
					if(array_key_exists($day,$events))
					{
						//adding the date_has_event class to the <td> and close it
						echo ' class="date_has_event"> '.$day;

						//adding the eventTitle and eventContent wrapped inside <span> & <li> to <ul>
						echo '<div class="events"><ul>'.$events[$day].'</ul></div>';
					}
					else 
					{
						//if there is not event on that date then just close the <td> tag
						echo '> '.$day;
					}

					echo "</td>";
				}
				else 
				{
					//showing empty cells in the first and last row
					echo '<td class="padding"> </td>';
				}
			}
			echo "</tr><tr>";
		}

		?>
	</tr>
	<tfoot>		
		<th>
			<a href="<?=$_SERVER['PHP_SELF']?>?time=<?=$previous_year?>" title="<?=$previous_year_text?>">««</a>
		</th>
		<th>
			<a href="<?=$_SERVER['PHP_SELF']?>?time=<?=$previous_month?>" title="<?=$previous_month_text?>">«</a>
		</th>
		<th> </th>
		<th> </th>
		<th> </th>
		<th>
			<a href="<?=$_SERVER['PHP_SELF']?>?time=<?=$next_month?>" title="<?=$next_month_text?>">»</a>
		</th>
		<th>
			<a href="<?=$_SERVER['PHP_SELF']?>?time=<?=$next_year?>" title="<?=$next_year_text?>">»»</a>
		</th>		
	</tfoot>
</table>
</body>
</html>

Ficainde bem pessoal

Link to comment
Share on other sites

Boas pessoal, ando com um erro no meu agendamento, o seguinte erro que se dá é este:

Notice: Undefined offset: 16 in C:\wamp\www\sibd06\agendamento.php  on line 37

O array events não tem nenhum conteúdo correspondente ao índice 16. Quando tentas adicionar texto a esse a esse índice (via .=), dá essa notice, para te avisar que o código não é do mais católico, se bem que vai funcionar à mesma.

"Para desenhar um website, não tenho que saber distinguir server-side de client-side" - um membro do fórum que se auto-intitula webdesigner. Temo pelo futuro da web.

Link to comment
Share on other sites

Isso n corrige o erro só o suprime.

"[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31

Life is a genetically transmitted disease, induced by sex, with death rate of 100%.

Link to comment
Share on other sites

já resolvi, meti isso no topo da pagina

"// Report all errors except E_NOTICE

error_reporting(E_ALL ^ E_NOTICE);"

Isso n corrige o erro só o suprime.

Exactamente. Só se deve desligar o relatório de erros, warnings e notices em servidores de produção, e depois de se saber exactamente o que se está a fazer.

Nesse caso do array, só tens que garantir que a posição a acrescentar tem alguma coisa, via isset, por exemplo. Se tiver, acrescentas, se não tiver, atribuis.

"Para desenhar um website, não tenho que saber distinguir server-side de client-side" - um membro do fórum que se auto-intitula webdesigner. Temo pelo futuro da web.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.