Jump to content

[SOLVED] my script work but some errors is displayed


prince198

Recommended Posts

hi every body

first thak you for people helping me for function like to_days() in my sql

so

i have this script

$nbrdays[ ] = 0; 


			  
	        

	          $To_days_start=to_days('2008-01-01');
	          $To_days_end=to_days('2008-03-03');
	          $Get_week =date('W',strtotime('2008-01-01'));
	          $week= trim($Get_week, 0);
	          $day_week=date('N',strtotime('2008-01-01'));
		         

	for( $day = $To_days_start; $jour <= $To_days_end; $day++ ) 
                           { 
					   
                           if( $day_week >= 1 AND$day_week < 7 ) 
                           $nbrdays[$week-1]++; 
              $day_week++; 
                           if( $day_week > 7 ) 

			     {

			           $week++; $day_week= 1;
			     
				       }
				       }


print_r($nbrdays)

and i have result that i'm looking for :number day by week without sunday


Array ( [0] => 5 [1] => 6 [2] => 6 [3] => 6 [4] => 6 [5] => 6 [6] => 6 [7] => 6 [8] => 6 [9] => 1 )

but with this errors


Notice: Undefined offset: 1 in.....

Notice: Undefined offset: 2 in ..

Notice: Undefined offset: 3 in ..

Notice: Undefined offset: 4 in ..

Notice: Undefined offset: 5  ...

i don't understand why i have errors although that i have now the result that i'm looking for

hi,

 

you're incrementing an array value when the index is not set.

 

change

 

<?php

$nbrdays[$week-1]++; 

?>

 

to

 

<?php

if(!isset($nbrdays[$week-1]))
{
    $nbrdays[$week - 1] = 0;	
}
$nbrdays[$week-1]++; 
?>

 

should fix it.

 

make sure you put curly brackets { } after your conditional statements.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.