0

I try to create loop for select box for select time start 8.00 and increasing it continusly for this matter i found solution from creating a loop for time incremented by 15 minutes but i put it into my code under array it shows only one time but i use var_dump($timeinoption) it shows correctly as

array (size=1)
  '8 . 0' => string '8 . 0' (length=5)

array (size=1)
  '8 . 15' => string '8 . 15' (length=6)

array (size=1)
  '8 . 30' => string '8 . 30' (length=6)

array (size=1)
  '8 . 45' => string '8 . 45' (length=6)

array (size=1)
  '9 . 0' => string '9 . 0' (length=5

but codeignaiter select box not work;

form_dropdown('timein',$timeinoption,'8.30');

it shows only one time on select box

echo form_label('Time Start','timestart');

for ($i = 8; $i <= 17; $i++)
{
  for ($j = 0; $j <= 45; $j+=15)
  {
    //inside the inner loop
    $opti= $i.' . '. $j;
    $timeinoption=array($opti=>$opti) ;
    }
  //inside the outer loop


}

echo form_dropdown('timein',$timeinoption,'8.30');


     ?>
0

3 Answers 3

1

You are overwriting your array on each loop

$timeinoption=array($opti=>$opti);

So there will only be 1 value in your array.

Try changing to

$timeinoption[$opti]= $opti;
Sign up to request clarification or add additional context in comments.

Comments

1

You have to array inside the loop :

$timeinoption = array();
for ($i = 8; $i <= 17; $i++)
{
  for ($j = 0; $j <= 45; $j+=15)
  {
    //inside the inner loop
    $opti= $i.' . '. $j;
    $timeinoption[$opti]  = $opti;
    }
  //inside the outer loop    

}

Comments

0

Easy Way to Put loop Dropdown in CI

$d_opt = array(0 => 'DD');

for($i=1;$i<=31;$i++)
{
    if(strlen($i)<2)
    {
        $i = 0 . $i;    
    }
    $d_opt[$i]=$i;
}

echo form_dropdown('date',$d_opt);

1 Comment

This does not appear to produce the expected output of 8:00, 8:15, 8:30... that the OP asked for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.