Dropdown in a form

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.


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.


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.


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.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.