如何从期权选择中获取价值?

时间:2014-09-11 14:06:14

标签: php mysql codeigniter

如何从选项值中将值放入mysql中? 这是我的代码来自文件" visitor_model.php"。

public function month_visitor() {

    $month_query = $this->db->query('SELECT * FROM data_visitor WHERE MONTH(date)=X');

    return $month_query->result();

}

这是我在文件" visitor_table.php"

中的选项代码
<div class="row text-center">
 <h1 id="visitor_table">Visitor Table</h1>

<form action="<?php echo site_url('month_visitor');?>" method="get">
 <div>
  <label for="nomor" class="col-md-2">
    Month :
  </label>
  <div class="col-md-9">
    <select name="month" class="form-control" id="month">
      <option>All</option>
      <option value='1'>January</option>
      <option value='2'>February</option>
      <option value='3'>March</option>
      <option value='4'>April</option>
      <option value='5'>May</option>
      <option value='6'>June</option>
      <option value='7'>July</option>
      <option value='8'>August</option>
      <option value='9'>September</option>
      <option value='10'>October</option>
      <option value='11'>November</option>
      <option value='12'>December</option>
    </select>
  </div>
</div>

我想从

填充X.
$month_query = $this->db->query('SELECT * FROM data_visitor WHERE MONTH(date)=X');

来自期权​​的价值。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

在PHP中,只需将参数month绑定到查询中$this->input->get('month')

$month_query = $this->db->query('SELECT * FROM data_visitor WHERE MONTH(date)=?', array($this->input->get('month')));