Welcome Guest, Not a member yet? Register   Sign In
Single quotes, for loop and type casting
#1

[eluser]muhax[/eluser]
Ok guys. This is probably more of a PHP rather than Codeigniter question, but here it goes anyway...
Here is my problem.
I'm doing some coding in CodeIgniter.
I fetch stuff from the database

PHP Code:
Code:
$mnsy = $min_semester_year->row();
$mxsy = $max_semester_year->row();



These two basically contain (using print_r($mnsy)):
stdClass Object ( [max_semester] => spring [max_year] => 2010 )
stdClass Object ( [min_semester] => fall [min_year] => 2008 )

Code:
$min_semester =$mnsy->min_semester;
echo $min_semester;
$max_semester = $mnsy->min_year;
echo $max_semester;
$min_year = $mxsy->max_semester;
echo $min_year;
echo br(1).gettype($min_year);  
$max_year = $mxsy->max_year;
echo $max_year;


If I run this on a loop

Code:
for ( $i = $max_year; $i>=$min_year; $i--)


the loop goes wild and either does not execute at all, or starts going from 2010 down to God knows where.
I even tried type casting

Code:
for ( $i = (int)$max_year; $i>=(int)$min_year; $i--)


and again the same thing

However if I use direct assigning with single quotes, it works perfectly.
That is if I assign the same stuff that I would get from that array by hard-coding it, then it all works out. I ran gettype on the previous example and this one below and all of these give me string, however the first does not work while the one below does.


Code:
$min_semester = 'fall';
$max_semester = 'spring';
$min_year = '2008';
$max_year = '2010';
echo br(1).gettype($min_year);




Code:
for ( $i = $max_year; $i>=$min_year; $i--)



What seems to be the problem here?
#2

[eluser]danmontgomery[/eluser]
Code:
$min_year = $mxsy->max_semester;
#3

[eluser]muhax[/eluser]
Yea, fixed that one...My bad SmileSmileSmile...




Theme © iAndrew 2016 - Forum software by © MyBB