CodeIgniter Forums
Dropdown in a form - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Dropdown in a form (/showthread.php?tid=30068)



Dropdown in a form - El Forum - 05-02-2010

[eluser]maniac[/eluser]
I am trying to add a dropdown list in a form instead of using a text box for the information to be added, but it keeps coming up blank. Can anyone help me with what I am doing wrong?

My code on the view page -

<form action="http://localhost/aStage2CI/index.php/results/insertresult" method="POST">
<p class ="bold">Course ID:<br />
<select name="Select">
&lt;?php foreach($result as $row):?&gt;
<option value="&lt;?echo $row->courseid?&gt;">
&lt;?echo $row->courseid?&gt;</option>
&lt;?php endforeach;?&gt;
</select></p> ..........&lt;/form&gt;

The actual form worked well with just the text boxes.

Thanks


Dropdown in a form - El Forum - 05-02-2010

[eluser]Unknown[/eluser]
hi, i'm a bit of a noob to CI, but i'm fairly sure you're missing a semi-colon (Wink after '->courseid' and before the ?&gt;

hope that helps.


Dropdown in a form - El Forum - 05-02-2010

[eluser]maniac[/eluser]
Hi,

I am very new to this too, but get lots of help here.

I am missing the semicolon, but didn't help with the problem.

Thanks


Dropdown in a form - El Forum - 05-02-2010

[eluser]pickupman[/eluser]
Try this:
Code:
$dropdown = array('FALSE' => 'Please Select'); //Create array

foreach($result as $row){
  $dropdown[$row->courseid] = $row->courseid; //Add item to array
}

echo form_dropdown('select',$dropdown); //Print drop down

Make sure that the variable $result is the result object and not a query object. (ie. Somewhere you have passed $result = $some_query->result(); Otherwise, it won't work. Please use the <code> button when posting code into the forums. It will make it easier for people to copy and pasted your code.