我有几个复选框可以从数据库中过滤我的元素,但我不知道如何应用具有最小值和最大值的过滤器,因为从我的视图中我只能传递给控制器一个值我的投入
例如:我想将1000到1500之间的价格过滤器应用于元素
查看:
<li><input type="checkbox" name="price[]" value="1000"> <1.000</li>
<li><input type="checkbox" name="price[]" value="1500"><a href="#">1.000 - 1.500</a></li>
<li><input type="checkbox" name="price[]" value="2000"><a href="#">1.500 - 2.000</a></li>
<li><input type="checkbox" name="price[]" value="3000"><a href="#">2.000 - 3.000</a></li>
<li><input type="checkbox" name="price[]" value="4000"><a href="#">3.000 - 4.000</a></li>
<li><input type="checkbox" name="price[]" value="5000"><a href="#">4.000 - 5.000</a></li>
<li><input type="checkbox" name="price[]" value="5000"><a href="#"> >5.000</a></li>
控制器:
public function laptops()
{
$filter = $this->input->post();
$data['laptops_toate'] = $this->emag_model->laptops_toate_grid($filter);
$this->load->view('emag/laptops',$data);
型号:
public function laptops_toate_grid($filter = null){
$this->db->select('*')
->from('laptop_notebook')
->join('brands','brands.id_brands = laptop_notebook.brand');
if($filter['price']){
$this->db->where('price <', $filter['price']);
}
$query = $this->db->get()->result();
return $query;
}
答案 0 :(得分:1)
只是想知道如何做到这一点。
视图文件:
class MainActivity extends Activity {
protected EditText textVoice;
Button button;
TextToVoice textToVoice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ln_dialog);
textVoice = (EditText) findViewById(R.id.textVoice);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textToVoice = new TextToVoice(MainActivity.this,textVoice.getText().toString());
textToVoice.listenVoice();
}
});
}
public class TextToVoice extends MainActivity {
String textString;
Context context;
public TextToVoice(Context c ,String s) {
textString = s;
context = c;
}
public void listenVoice() {
makeVoice();
}
public void downloadVoice() {
}
public void makeVoice() {
Toast.makeText(context, makeUrl(), Toast.LENGTH_SHORT).show();
}
private String makeUrl() {
if (textString.contains(" ")) {
textString = textString.replace(" ", "+");
}
return textString;
}
}
控制器保持不变。
该模型变为:
<li><input type="checkbox" name="price[]" value="<1000"> <1.000</li>
<li><input type="checkbox" name="price[]" value="1000-1500"><a href="#">1.000 - 1.500</a></li>
<li><input type="checkbox" name="price[]" value="1500-2000"><a href="#">1.500 - 2.000</a></li>
<li><input type="checkbox" name="price[]" value="2000-3000"><a href="#">2.000 - 3.000</a></li>
<li><input type="checkbox" name="price[]" value="3000-4000"><a href="#">3.000 - 4.000</a></li>
<li><input type="checkbox" name="price[]" value="4000-5000"><a href="#">4.000 - 5.000</a></li>
<li><input type="checkbox" name="price[]" value=">5000"><a href="#"> >5.000</a></li>
注意:这只是一个有用的想法,我还没有对代码进行过测试。