0

I'm developing a drop-down form with values from a database. My question is how can I display values from the database to the drop-down without displaying the same values. I have 2 data in my database which consist of the same value (Paid) but when I display it on my dropdown it shows 2 "Paid" values instead of one.

Thank you

Here is my Model :

public function getLiveEvents(){
    $query = $this->db->get('live_events');
    return $query->result();
}

Here is my View :

 <label class="control-label" for="name">Ticket type:</label>
            <select name="type" class="form-control input-md">
                <?php
                        foreach ($sort as $sorts) {

                            echo '<option value="' . $sorts->live_type . '">' . $sorts->live_type.'</option>';
                        }
                        ?>

            </select>        
1
  • So U want to ignore repeated values right? Commented Mar 16, 2018 at 4:02

2 Answers 2

2

One solution is that you could filter the data on the query :

public function getLiveEvents(){
    $this->db->distinct();
    $this->db->select('live_type');
    $query = $this->db->get('live_events');
    return $query->result();
}
Sign up to request clarification or add additional context in comments.

1 Comment

tried your solution but still gave me 2 options with same value
1

This should work -

public function getLiveEvents(){
    $this->db->distinct();
    $this->db->select('live_type');
    $this->db->group_by('live_type'); 
    $query = $this->db->get('live_events');
    return $query->result();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.