只想让笨过滤器形式的工作。 例如,如果“三星”将被从下拉列表中的“2G”选择从选框字段,行id为1和4应返回。 但我的模型返回nothing.I认为这个问题是在模型的IF语句,但我无法找出什么是确切的原因。 请帮我。
这里是我的数据库表:
这是我的filter:
这里是我的模型:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Model_example extends CI_Model {
function __construct()
{
parent::__construct();
}
public function did_filter() {
$types = $this->input->post('types');
$data = array(
'2g' => 0,
'3g' => 0,
'4g' => 0,
);
foreach ($types as $type) {
$data[$type] == 1;
}
$this->db->select('*');
$this->db->from('table_example');
$this->db->where('phone', $this->input->post('phone'));
if (
$query = $this->db->get()
)
{
if (
(('2g' == 1) AND ($data['2g'] == 1)) OR
(('3g' == 1) AND ($data['3g'] == 1)) OR
(('4g' == 1) AND ($data['4g'] == 1)))
{
return $result = $query->result_array();
}
else {
return false;
}
}
else {
return false;
}
}
}
这是我的看法数1:
<?php
$this->load->helper("form","file");
echo validation_errors();
echo form_open_multipart("example/search");
echo form_label("Phone:<br>","phone");
$data = array(
"" => "Select Phone",
"samsung" => "Samsung",
"htc" => "HTC",
"nokia" => "Nokia",
);
echo form_dropdown('phone', $data, set_value('phone'));
echo br(5);
?>
<?php echo form_label("Network Type:<br>","type");?>
<input type="checkbox" name="types[]" value="2g" id="types" <?php echo set_checkbox('types[]', '2g', FALSE); ?>/>2G<br />
<input type="checkbox" name="types[]" value="3g" id="types" <?php echo set_checkbox('types[]', '3g', FALSE); ?>/>3G<br />
<input type="checkbox" name="types[]" value="4g" id="types" <?php echo set_checkbox('types[]', '4g', FALSE); ?>/>4G<br />
<br />
<?php
echo br(1);
echo form_submit("filterSearch", "Search");
echo form_close();
?>
这是我的看法号2:
<?php
print_r($result);
这里是我的控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Example extends MX_Controller {
public function index() { //main function
$this->load->view("view_example");
}
public function search() {
$this->load->library('form_validation');
$this->load->model('model_example');
$this->form_validation->set_rules('phone', 'Phone','required');
$this->form_validation->set_rules('types[]', 'Network Type','required');
if($this->form_validation->run()) {
$data["result"] = $this->model_example->did_filter();
$this->load->view("view_search_results",$data);
}
else
{
$this->load->view("view_no_search_results");
}
}
}