Question

I am trying to call $data['form_value'] from view in Codeigniter, but that array returns empty.

Here is my Controller:

$data['field'] = $this->cc->get_form_names($data['selid']);
foreach($data['field'] as $key=>$valuee) {
    $data['form_value'] = $this->cc->get_form_value($valuee->select);
}

Now in the View:

foreach($field as $key=>$valuee) {
    echo "<span\"> ".$valuee->disp_name." :</span>";
    <select name=\"\">";
    foreach($form_value as $v=>$vv) {
        $value = $vv->select;
        echo "<option value=\"".$vv->select."\" >".$vv->select."</option>";
    }
    echo"</select> ";
}

When I do var_dump($form_value) it return array(0) { }

How would I get that variable?

Était-ce utile?

La solution

You are overwriting form_value in loop. Try below code in your controller.

$form_value = array();
foreach($data['field'] as $key=>$valuee) {
    $form_value[] = $this->cc->get_form_value($valuee->select);
}
$data["form_value "] = $form_value ;

Autres conseils

Modify your Controller code like this,

$data['field'] = $this->cc->get_form_names($data['selid']);

foreach($data['field'] as $key=>$valuee) {
    $data['form_value'][] = $this->cc->get_form_value($valuee->select);
}

$data['form_value'] should be an array to loop through it. You are using it as string and trying to loop through it.

Hope this helps :)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top