Jump to content

index undefined


Stickybomb

Recommended Posts

ok i am working on a simple event system, bsically i pass the information from the database to an array for a given month then use the array to wirte the events. for some reason though i am getting index undefined for each day

 

heres the code i am using to create the array

 


$vEvent = array();
$vD = array();
$vM = array();
$vY = array();
$vId = array();
$vTitle = array();

$i=0;
while($row = mysql_fetch_array($vResults)){

$vD[$i]=$row['event_day'];
$vM[$i]=$row['event_month'];
$vY[$i]=$row['event_year'];
$vId[$i]=$row['event_id'];
$vTitle[$i]=$row['event_title'];

$i++;
}

$y=1;
for($i=1;$i<=$days['mday'];$i++){

$vEvent[$i] = '<ul>';

for($x=0;$x<sizeof($vD);$x++){

	if($vY[$x]==$vYear && $vM[$x]==$vMonth && $vD[$x]==$i){

		$vEvent[$i].='<li>';
		$vEvent[$i].='<a href="" onclick="event-'.$y.'.style.visibility=\'visible\';">';
		$vEvent[$i].=$vTitle[$x];
		$vEvent[$i].='</a>';
		$vEvent[$i].='</li>';
		$y++;

	}

}

$vEvent[$i] .= '</ul>';

}

 

i can not seem to figure this one out any help is greatly appriciated thnks sticky ;)

Link to comment
Share on other sites

the error is when i am trying to read the value stored in the array basically i just use a for loop to go through each day of the month and pass the array value for that day to a variable to be echoed like this

 

$vCalendar = $vEvent[$i]

 

it is giving me an undefined offset:1,2,3... error for each value of $i 1-30 or however many days in that month

Link to comment
Share on other sites

 

this is the entire code

 


//calendar write function
//$vResults = the results from the events query
//$vMonth = month to print
//$vYear = year to print
//creates th calendar then returns the code
function fWriteCalendar($vResults,$vMonth,$vYear){
$vCalendar=array();
    // Get key day informations. 
    // We need the first and last day of the month and the actual day
    $today  = getdate();
    $temp1 = getdate(mktime(0,0,0,$vMonth,1,$vYear));
    $temp2 = getdate(mktime(0,0,0,$vMonth+1,0,$vYear));
    $temp3 = getdate(mktime(0,0,0,$vMonth,1,$vYear));
    $introoffset = $temp1['wday'];
    $closeoffset = $temp2['wday'];
    $days=$temp2['mday'];
    $month=$temp3['month'];

    $actday = 1;
    
//get event data
$vEvent = array();
$vD = array();
$vM = array();
$vY = array();
$vId = array();
$vTitle = array();

$i=0;
while($row = mysql_fetch_array($vResults)){

$vD[$i]=$row['event_day'];
$vM[$i]=$row['event_month'];
$vY[$i]=$row['event_year'];
$vId[$i]=$row['event_id'];
$vTitle[$i]=$row['event_title'];

$i++;
}

$y=1;
for($i=1;$i<=$days['mday'];$i++){

$vEvent[$i] = '<ul>';

for($x=0;$x<sizeof($vD);$x++){

	if($vY[$x]==$vYear && $vM[$x]==$vMonth && $vD[$x]==$i){

		$vEvent[$i].='<li>';
		$vEvent[$i].='<a href="" onclick="event-'.$y.'.style.visibility=\'visible\';">';
		$vEvent[$i].=$vTitle[$x];
		$vEvent[$i].='</a>';
		$vEvent[$i].='</li>';
		$y++;

	}

}

$vEvent[$i] .= '</ul>';

}
    
    // Set begining information
    $vCalendar[0] = '<div id="calendar-main">';
    $vCalendar[1] = '';
    $vCalendar[2] = '<div id="calendar-header">';
    $vCalendar[2] .= ' Calender of Events for ';
    $vCalendar[2] .= $month;
    $vCalendar[2] .= '-';
    $vCalendar[2] .= $vYear;
    $vCalendar[2] .= '</div>';
    $vCalendar[3] = '';
    $vCalendar[4] = '<div id="calendar-week">Sunday</div>';
    $vCalendar[5] = '<div id="calendar-week">Monday</div>';
    $vCalendar[6] = '<div id="calendar-week">Tuesday</div>';
    $vCalendar[7] = '<div id="calendar-week">Wednesday</div>';
    $vCalendar[8] = '<div id="calendar-week">Thursday</div>';
    $vCalendar[9] = '<div id="calendar-week">Friday</div>';
    $vCalendar[10] = '<div id="calendar-week">Saturday</div>';
    $vCalendar[11] = '<div id="clear"></div>';
    $vCalendar[12] = '';
    $x=13;
    
    //Display First week
    
    // Display the intro blanks
    for($i=0;$i<$introoffset;$i++){
        $vCalendar[$x] = '<div id="calendar-blank-day"></div>';
        $x++;
    }
    
    // Display the first week
    for($i=$introoffset;$i<7;$i++){
    if($actday==$today['mday']){
    		$vCalendar[$x] = '<div id="calendar-day-current">

			<div id="day">'.$actday.'</div>
			<div id="events">'.$vEvent[$actday].'</div>

		</div>';
    }else{
    		$vCalendar[$x] = '<div id="calendar-day">

			<div id="day">'.$actday.'</div>
			<div id="events">'.$vEvent[$actday].'</div>

		</div>';
    }
        $actday++;
        $x++;
    }
    
    $vCalendar[$x] = '<div id="clear"></div>';
    $x++;
    
    //Display full weeks
    //Get how many complete weeks are in the actual month
    $fullWeeks = floor(($days-$actday)/7);
    for ($i=0;$i<$fullWeeks;$i++){
    
        //Display full week
        for ($j=0;$j<7;$j++){
	      if($actday==$today['mday']){
    		$vCalendar[$x] = '<div id="calendar-day-current">

			<div id="day">'.$actday.'</div>
			<div id="events">'.$vEvent[$actday].'</div>

		</div>';
    }else{
    		$vCalendar[$x] = '<div id="calendar-day">

			<div id="day">'.$actday.'</div>
			<div id="events">'.$vEvent[$actday].'</div>

		</div>';
    }
        $actday++;
        $x++;
        }
        
        $vCalendar[$x] = '<div id="clear"></div>';
    	$x++;
    }
    
    //Display Last Week
    //Now display the rest of the month
    while ($actday <= $days){
        if($actday==$today['mday']){
    		$vCalendar[$x] = '<div id="calendar-day-current">

			<div id="day">'.$actday.'</div>
			<div id="events">'.$vEvent[$actday].'</div>

		</div>';
    }else{
    		$vCalendar[$x] = '<div id="calendar-day">

			<div id="day">'.$actday.'</div>
			<div id="events">'.$vEvent[$actday].'</div>

		</div>';
    }
        $actday++;
        $x++;
        }
    	
for ($i=($closeoffset+1);$i<7;$i++){
      	$vCalendar[$x] = '<div id="calendar-blank-day"></div>';
      	$x++;
}
        
    $vCalendar[$x] = '<div id="clear"></div>';
    $x++;
    
    $vCalendar[$x] =  '</div>';
   
   	//Write Calendar
    for($i=0;$i<sizeof($vCalendar);$i++){
	echo $vCalendar[$i]."\n";
}
}

 

i am geting the errors on the lines with this code

 

Notice: Undefined offset: 1

 

happens for the whole array 1-30

 


<div id="events">'.$vEvent[$actday].'</div>

Link to comment
Share on other sites

You are accessing a variable that isn't set you have 2 options.

1. Code for notices (meaning code in a way as to prevent notices from happening)

2. Turn them off

error_reporting(E_ALL ~ notices);

That should turn off notices and only show all the other standard errors.

 

Notices are small issues, and small things.  you would be wise to try coding with them, so you can avoid major mistakes, it takes a little extra time but it's worth it later when you learn how to naturally avoid them,and you will have more reliable, more server portable code when everything is done.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.