Welcome Guest, Not a member yet? Register   Sign In
doesn't work sprintf
#1

[eluser]dimaomni[/eluser]
hello, dear experts

I have that piece of code:
Code:
&lt;? for($day_of_month=1; $day_of_month<=31; $day_of_month++) {
        $mark = $dates[$date1 = sprintf('2010-04-d', $day_of_month)];
?&gt;
But must be sprintf('2010-04-percent02d'...

and it involve problem:

A PHP Error was encountered
Severity: Notice
Message: Undefined index: 2010-04-04 etc...

I've just pasted this piece of code in php file and it work ok, but in CI dosen't work


thanks!
#2

[eluser]WanWizard[/eluser]
And, is the variable $dates['2010-04-04'] defined?
Because the error message says it isn't...

Where do you define this array? And how?
#3

[eluser]dimaomni[/eluser]
yes
in message it appears
Message: Undefined index: 2010-04-04
#4

[eluser]dimaomni[/eluser]
if I
Code:
print_r($dates);
I get result:
Array
(
[2010-04-01] => 2
[2010-04-09] => 7
[2010-04-11] => 5
[2010-04-25] => 0
)
Array
(
[2010-04-01] => 2
[2010-04-09] => 7
[2010-04-11] => 5
[2010-04-25] => 0
)

Code:
foreach ($query as $row)    
{
  $lessons[$lesson_id][$date] = $mark;
}
....  
foreach ($lessons as $lesson => $dates)
{
$day_of_month = 01;// vary from 01-31
....
$mark = $dates[$tmp = sprintf('2010-04-d', $day_of_month)];
}
#5

[eluser]WanWizard[/eluser]
So, $dates['2010-04-04'] does not exist. And the index is indeed undefined.
#6

[eluser]dimaomni[/eluser]
I don't understand why, could you explain ?
I've confused, because I can print this array.


thanks
#7

[eluser]WanWizard[/eluser]
I can't explain. You say that your $dates array contains
Quote:Array
( [2010-04-01] => 2
[2010-04-09] => 7
[2010-04-11] => 5
[2010-04-25] => 0
)
So all I can say is that PHP is right: the requested index does not exist. So either your code to fill $dates is wrong, or you need to check if the index exists before referencing it.
#8

[eluser]dimaomni[/eluser]
Thanks a lot !!!




Theme © iAndrew 2016 - Forum software by © MyBB