Welcome Guest, Not a member yet? Register   Sign In
Dropdown in a form
#1

[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
#2

[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.
#3

[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
#4

[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.




Theme © iAndrew 2016 - Forum software by © MyBB