Foros del Web » Programando para Internet » PHP »

Error (Notice: Undefined offset: 21 in C:\xampp\htdocs\eventcal\calendar.php on line

Estas en el tema de Error (Notice: Undefined offset: 21 in C:\xampp\htdocs\eventcal\calendar.php on line en el foro de PHP en Foros del Web. Que tal amigo estoy intentanto realizar un calendario de eventos el problema que tengo que al ingresar un evento a la BD y mostrar el ...
  #1 (permalink)  
Antiguo 02/07/2012, 20:48
 
Fecha de Ingreso: agosto-2011
Mensajes: 11
Antigüedad: 12 años, 8 meses
Puntos: 1
Pregunta Error (Notice: Undefined offset: 21 in C:\xampp\htdocs\eventcal\calendar.php on line

Que tal amigo estoy intentanto realizar un calendario de eventos el problema que tengo que al ingresar un evento a la BD y mostrar el calendario me sale este error:

Notice: Undefined offset: 21 in C:\xampp\htdocs\eventcal\calendar.php on line 37

espero puedan ayudarme a dar solucion a este problema ya que se estaba tratando en el foro por juan007 pero ya lo cerraron y su solución no me funciona este es su link por si quieren consultar: http://www.forosdelweb.com/f18/notice-undefined-offset-20-c-wamp-www-portal-calendario-php-line-76-a-780129/

pongo el php que uso saludos:

Código PHP:
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();


$result mysql_query("SELECT DATE_FORMAT(eventDate,'%d') AS day,eventContent,eventTitle FROM eventcal 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))
{
    
//El error me lo marca en este linea de abajo
    
$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);

 
(for Sundaythrough 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);
?> 
  #2 (permalink)  
Antiguo 03/07/2012, 16:56
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Error (Notice: Undefined offset: 21 in C:\xampp\htdocs\eventcal\calendar.p

Código PHP:
Ver original
  1. $events = array();
  2.  
  3. $result = mysql_query("SELECT DATE_FORMAT(eventDate,'%d') AS day,eventContent,eventTitle FROM eventcal WHERE eventDate BETWEEN  '$current_year/$current_month/01' AND '$current_year/$current_month/$total_days_of_current_month'");
  4.  
  5. while($row_event = mysql_fetch_object($result))
  6. {
  7.     //El error me lo marca en este linea de abajo
  8.     $events[intval($row_event->day)] .= '<li><span class="title">'.stripslashes($row_event->eventTitle).'</span><span class="desc">'.stripslashes($row_event->eventContent).'</span></li>';
  9. }

$events es un array vacío, no hay elementos, intentas concatenar algo a un elemento que no existe y es cuando obtienes el mensaje.

La solución es sencilla, si no existe el elemento, lo creas con un valor inicial y listo; ejemplo:

Código PHP:
Ver original
  1. if( ! isset($arreglo['elemento'])) {
  2.     $arreglo['elemento'] = '';
  3. }
  4. $arreglo['elemento'] .= '¡Ya puedo concatenar sin problemas!';
__________________
- León, Guanajuato
- GV-Foto

Etiquetas: line, mysql, notice, offset, undefined
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:22.