CodeIgniter Forums
Dropdown in a form - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived General Discussion (
+--- Thread: Dropdown in a form (/thread-30068.html)

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

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.


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

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


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.


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

Try this:
$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.