[eluser]brucebat[/eluser]
Hi all,
I am taking a variable called
$formdata that is passed to my view from my controller.
This variable contains all the rows from a table called "Staff" in my database and I want it to populate my pulldown menu in my form.
This is a printf of the variable showing that it contains data:
Quote:Array ( [0] => stdClass Object ( [staff_id] => 1 [name] => Cardiology Nurse ) [1] => stdClass Object ( [staff_id] => 2 [name] => Radiology Nurse ) [2] => stdClass Object ( [staff_id] => 3 [name] => Scrub Nurse ) [3] => stdClass Object ( [staff_id] => 4 [name] => Circulating Nurse ) [4] => stdClass Object ( [staff_id] => 5 [name] => Nurse ) [5] => stdClass Object ( [staff_id] => 6 [name] => Training Nurse ) [6] => stdClass Object ( [staff_id] => 7 [name] => Physiologist ) [7] => stdClass Object ( [staff_id] => 8 [name] => Radiographer ) [8] => stdClass Object ( [staff_id] => 9 [name] => Consultant ) [9] => stdClass Object ( [staff_id] => 10 [name] => Radiologist ) [10] => stdClass Object ( [staff_id] => 11 [name] => Cardiologist ) [11] => stdClass Object ( [staff_id] => 12 [name] => Anaethestist ) [12] => stdClass Object ( [staff_id] => 13 [name] => Non-medical Staff ) )
cpass77 and I have been trying to get it to then put these values in the form_dropdown function however it has been saying this error:
Quote:A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: helpers/form_helper.php
Line Number: 331
This is the code currently being used in the view:
Code:
for ($i=0; $i < 5; $i++)//creates five rows of fields for the form
{
foreach( $formdata as $row )
{
echo form_dropdown ( 'staff'.$i, $row->name, set_value ('staff'.$i) );
}
echo form_input ('staff_quantity'.$i, set_value ('staff_quantity'.$i));
echo form_input ('staff_sterilised'.$i, set_value ('staff_sterilised'.$i));
echo '<br/>';
}
Is this the best way of doing what I am trying to achieve or is there an easier way?
Thanks for your time!