Ramon Chaves Ramon Chaves - 4 months ago 9
PHP Question

Severity: Warning Message: Invalid argument supplied for foreach() Filename: helpers/form_helper.php

I have a dynamic select ? which carries the values ​​in another select . Charging is running . However displays this Message:

Severity: Warning Message: Invalid argument supplied for foreach() Filename: helpers/form_helper.php

This is my controller:

public function getparcelas()
{ if($this->input->post('aquiller'))
{
$parcelas = $this->input->post('aquiller');
$localidades = $this->sindico->get_parcelas($parcelas);
foreach($localidades as $fila)
{
?>
<option value="<?=$fila->numero_parcelas ?>"><?=$fila->numero_parcelas ?></option>
<?php
}
}
}}


My view : This is my view

$dados['album'] = $this->sindico->get_aquiller();
echo "<select name='aquiller' id='aquiller' class='form-control input-sm'>";
if (count($dados['album'])) {
foreach ($dados['album'] as $list) {
echo "<option value='". $list['id_alug'] . "'>" . $list['numero_apart'] . "-" . $list['nome_usu'] . "</option>";

}
}
echo "</select>";
echo form_dropdown('localidad', '', '', 'class="localidad" id="localidad"');


This is my javascript:

<script type="text/javascript">
$(document).ready(function() {
$("#somar").click(function(){
var total = 0;
$('.input').each(function(){
var valor = Number($(this).val());
if (!isNaN(valor)) total += valor;
});
$(".resultado").val(total.toFixed(2));
});
});
</script>
<script>
function calcular(){
var dt1 = document.getElementById("dt1").value;
var dt2 = document.getElementById("dt2").value;

var data1 = new Date(dt1);
var data2 = new Date(new Date(dt2));
var total = (data2.getFullYear() - data1.getFullYear())*12 + (data2.getMonth() - data1.getMonth());
document.getElementById("result").value = total;
}
</script>

Answer

You problem lies in form_helper.php means this line of code calling it.

echo form_dropdown('localidad', '', '', 'class="localidad" id="localidad"');

Now this function form_dropdown expect one parameter to be an array. It could be 2nd or third. Make sure you have read documentation to this function.