简体   繁体   中英

Codeigniter get where clause from input select

I need to get database information from table by using where clause from a select options.

My view:

<div>
    <select name="noSeats" class="form-control" placeholder="Seats">
        <option value="">Seats</option>
        <option value="45">45</option>
        <option value="49">49</option>
        <option value="51">51</option>
        <option value="53">53</option>
        <option value="56">56</option>
        <option value="57">57</option>
        <option value="61">61</option>
    </select>
</div>

My Model:

public function getSeats($noSeats) {
    $query = $this->db->get('seat');
    if ($query->num_rows() > 0) {
        return $query->result();
    }    
}

Also I have another problem with listing checkboxes; I need to list checkboxes in row of limit to 4 since I have many chechboxes.

在此处输入图片说明

您可以使用

$query = $this->db->where('COLUMN_NAME', $noSeats )->get('seat');
public function getSeats($noSeats){
      $query = $this->db->from('seat')->where('seat_col', $noSeats)->get();
      if($query->num_rows() > 0){
      return $query->result();
      }  
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM