Home > Software engineering >  How i called a data from the database in codeigniter
How i called a data from the database in codeigniter

Time:06-09

I have a form, this form called values from database. But i wanna show only one option accualy the first one. I dont need to other option. How can i set it ?

<select  id="slcCity">

                                                                    <option value selected disabled><?= getLang("Select City") ?></option>

                                                                    <?php foreach ($this->db->where("Status", "active")->where("ParentID", "0")->order_by("Order", "ASC")->get("location")->result() as $location) { ?>

                                                                        <option value="<?= $location->ID ?>"><?= $location->Title ?></option>

                                                                    <?php } ?>

                                                                </select><i ></i>

I dont know how to set it i dont have any codeigniter knowlodge. I just working on front side. enter image description here

CodePudding user response:

If you want to have the first record as the only option, add a limit to the query. ->limit(1)

<?php foreach ($this->db->where("Status", "active")->where("ParentID", "0")->order_by("Order", "ASC")->limit(1)->get("location")->result() as $location) { ?>

CodePudding user response:

Thank you for quick reply that's super thing thank you. Otherwise how can I set it the default value which is my first option in the drop-down ?

I mean i wanna set it automatically already selected option which is my first option value ?

  • Related