Codeigniter:从下拉列表中的选项中获取值并检查SQL条件

时间:2016-02-08 10:45:56

标签: php mysql codeigniter

我在从下拉列表中获取值以使用mysql查询检查条件时遇到问题。它使用codeigniter。让我发布下面包含的代码:

查看:

<select name="month" id="month">
        <option>Select Month</option>
        <option value="01">January</option>
        <option value="02">February</option>
        <option value="03">March</option>
        <option value="04">April</option>
        <option value="05">May</option>
        <option value="06">June</option>
        <option value="07">July</option>
        <option value="08">August</option>
        <option value="09">September</option>
        <option value="10">October</option>
        <option value="11">November</option>
        <option value="12">December</option>
    </select>

上述值应等于表格日期列中的月份。我将在下面发布我的模型:

MODEL:

$month = $this->input->post('month');
    $this->datatables->select('order_no,order_date,naturescrm_customers.name,total,naturescrm_users.username,naturescrm_order.id,
        naturescrm_order_status.status_name')
        ->unset_column('naturescrm_order.id')
        ->add_column('Actions', btn_edit('agent/order/edit/' . '$1').' '.get_view('$1','agent/order/view/') ,'naturescrm_order.id')
        ->from($this->_table_name)
        ->join("naturescrm_customers","naturescrm_customers.id=naturescrm_order.customer_id","left")
        ->join("naturescrm_order_status","naturescrm_order_status.status_id=naturescrm_order.order_status","left")
        ->join("naturescrm_users","naturescrm_users.id=naturescrm_order.user_id","left")
        ->where("DATE_FORMAT(order_date, '%m') = $month");
        $this->db->order_by("order_date","desc");

模型和视图中都有我的代码,所以当我在下拉列表中选择一个月时,数据库中提取的值应该基于月份反映出来。任何帮助都感激不尽。感谢

0 个答案:

没有答案