In Codeigniter how would I output all my database values into a selectbox? When I do the following I only get the first row outputted. It seems to cut off after the first. Any help?
<body>
<form method="post" action="<?=base_url()?>index.php/admin/addImg">
img url <input name="imgURL" type="text" /><br />
<br /> select project <select name="selectedProject">
<?php $query = $this->db->query("SELECT * FROM projects");
foreach ($query->result() as $row) { ?>
<option><?php echo $row->projectName.$row->projectId ?></option>
</select></form>
<?php } ?>
</body>
You’re closing your
selectwithin the first loop. Try something like this:Also, CodeIgniter provides a handy Form Helper for this type of thing.