Could you point a way to form a view's combo based on Codeigniter's results?

Eduardo Fuerte
Eduardo Fuerte used Ask the Experts™
on
Hi Experts

Could you point a way to form a view's combo based on Codeigniter's results?

Accordingly to:

Controller's code:
public function index() {

	// SELECT/DROPDOWN - Seguradora
	$fk_seguradora = $this->cliente_corporativo_model->new_get(array('query' => 'select * from system_seguradora'));
	$dropdown[0] = 'Selecione ...';
	foreach ($fk_seguradora as $key => $value)
		$dropdown[$value->id_seguradora] = $value->nome_seguradora;

	$this->data['fk_seguradora'] = form_dropdown('fk_seguradora', $dropdown, '', 'id="id_seguradora"');
	unset($dropdown);
	
	...

Open in new window



View's code:
The values are actually "hard coded"
  <div class="row">
	<div class="col-xs-12 mb15">
		<div class="input-group">
			<span class="input-group-addon ">
				<i class="fa fa-search c-gray"></i>
			</span>
			<span class="select">
				<select id="fk_seguradora" name="fk_seguradora">
					<option value="" selected="selected">...Cliente Corporativo...</option>
					<option value="1">Ace</option>
					<option value="2">Zurich</option>
					<option value="3">Banco Safra</option>
					<option value="4">SANTANDER</option>
					....
				</select>
			</span>
		</div>
	</div>
</div>

Open in new window


I tryed to do this way:
<div class="row">
	<div class="col-xs-12 mb15">
		<div class="input-group">
			<span class="input-group-addon ">
					<i class="fa fa-search c-gray"></i>
			</span>
			<span class="select">
				<select id="fk_seguradora" name="fk_seguradora">
				
                                  // A for-each at this point makes sense?? - I guess there is a better option.
				   <option value="<?php $id_seguradora?>"><?$fk_seguradora?></option>
 
						
				</select>
			</span>
			</label>
		</div>
	</div>
</div>

Open in new window


Thanks in advance!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Hey Eduardo,

You seem to already be creating the drop down in your Controller code by using the form_dropdown() method, so you would just need to echo that out in your view:

<?php echo $fk_seguradora ?>

Open in new window

Eduardo FuerteDeveloper and Analyst

Author

Commented:
Hi @Chris

You are perfectly right.

I'm the meanwhile I did this way:

 <div class="row">
                <div class="col-xs-12 mb15">                           
                    <!--label for="fk_seguradora" class="field-label text-muted mb10">Cliente Corporativo</label-->
                    <!--span class="input-group-addon "-->
                            <i class="fa fa-search c-gray"></i>
                    <!--/span-->
                    <label for="fk_seguradora" class="validar field select">
                        <?php echo $fk_seguradora; ?>
                        <i class="arrow double"></i>
                    </label>
                </div>
            </div>

Open in new window


Just a problem in correctly positionate the icon.
img001
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
That's more likely to be a CSS issues rather than a CodeIgniter one.
Eduardo FuerteDeveloper and Analyst

Author

Commented:
I'm going to ask another question on this particular subject, since it has derivated from the initial question.

Thanks for help!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial