Welcome Guest, Not a member yet? Register   Sign In
simple looping
#1

[eluser]metaltapimenye[/eluser]
i'm quiet new in OOP kind of stuff..
how can i make loop kind like $i++ kind of stuf?

i've make..
Code:
$year_present=date('Y');$data['year_present']=$year_present;
$e=$year_present-80;
while ($y >= $e) {
    $data['year_arr'] .= $y;
$y--; }

and put it to view with form helper with
Code:
form_dropdown('birthyear',$year_arr,$year_present)
but its stuck at 'while' part >_<
#2

[eluser]John_Betong[/eluser]
&nbsp;
What is the $y value before it enters the while loop?
&nbsp;
&nbsp;
&nbsp;
&nbsp;
#3

[eluser]Armchair Samurai[/eluser]
In order to use the form_dropdown function you need an associative array for the second parameter - at the moment you're passing it a string.
#4

[eluser]metaltapimenye[/eluser]
@John_Betong: sorry c/p problem occur.. rePaste n_n
Code:
$year_present=date('Y');$data['year_present']=$year_present;
$e=$year_present-80;
while ($year_present >= $e) {
    $year_arr[] .= array('$year_present'=>'$year_present');
$year_present--; }
$data['year_arr']=$year_arr;

@Armchair Samurai: yep, after i take my dropdown helper, its 2nd++ options just filled with 'Array'.. have any idea to make associative array in controller?

thx b4..
#5

[eluser]BoltClock[/eluser]
You're talking about a for loop. For your case I'd do this:

Code:
$year_present = date('Y');
$data['year_present'] = $year_present;

$e = $year_present - 80;
$year_arr = array();

for ($i = $year_present; $i >= $e; $i--)
{
    $i = strval($i); // Converts to string
    $year_arr[$i] = $i;
}

$data['year_arr'] = $year_arr;

You can just pass $year_arr in your view to the helper function as you did.

And there's absolutely no OOP to it Smile
#6

[eluser]metaltapimenye[/eluser]
problem solved..

@BoltClock: abselutely no OOP?.. (getting wikipedia, keysearch:OOP).. this OOP stuff make me kind a headache >_< .thx for your clue bro, i think i've got to taking more reference, and yours is one of it.

final result code repaste
Code:
$year_present=date('Y');$data['year_present']=$year_present;
$e=$year_present-80;
$year_arr=NULL;
while ($year_present >= $e) {
    $year_arr[] .= $year_present;
$year_present--; }
$data['year_arr']=$year_arr;
thx guys..
#7

[eluser]eggshape[/eluser]
hi metalapimenye,

your code might have a bug on line 5:

Code:
$year_arr[] .= $year_present

do you mean to push the new $year_present into the array? if you're going to use $year_arr as the options array, like Armchair said, you need to pass an associative array:

Code:
$year_arr[$year_present] = $year_present

which will give you this options list in html:

Code:
<options value="2007">2007</options>
<options value="2006">2006</options>
...
#8

[eluser]Grahack[/eluser]
I confirm (if only there was a need to) absolutely no OOP here.
#9

[eluser]wiredesignz[/eluser]
More like Oops!
#10

[eluser]syntax error[/eluser]
Code:
$data['year_present'] = $year_present = date('Y');
$e = $year_present-80;
while ($year_present >= $e) {
    $data['year_arr'][] = $e;
    $e++;
}

form_dropdown('birthyear', $data['year_arr'],$data['year_present'])




Theme © iAndrew 2016 - Forum software by © MyBB