douxingti9307 2009-11-25 13:18
浏览 7
已采纳

使用多个选择元素的值创建搜索?

I am working in PHP(with Symfony Framework) and i want to create a search based on multiple values selected from multiple selection element, i.e there will be multiple selection dropdown elements for like countries, cities, age etc.. and the values from them will query a data table and give the desired search output. (all values are not mandatory, will work with atleast one value). the idea will also do..

  • 写回答

1条回答 默认 最新

  • dongwuqi4243 2009-11-28 13:04
    关注

    I am using Symfony as framework, so my code goes like this,

    In Action,

    $values=$this->form->getValues();
    $nation=$values['nation'];
    $township=$values['township'];
    $job=$values['job'];
    $programming_language_known=$values['programming_language_known'];
    if($nation != null || $township != null || $job != null || $programming_language_known != null){
    //calling the function 
    $this->search_data=Jobs::jobSearch(...parameter's here...);  
    }else{ // search_data = null }
    

    in Model

    public static function jobSearch($nation=null, $township=null, $job=null, $programming_language=null)
    {
       $c=new Criteria();
       if($nation != null)
       {
          $c->addAnd(JobsPeer::NATION,$nation);
       } 
       if($township != null)
       {
          $c->addAnd(JobsPeer::TOWNSHIP,$township);
       }
       if($job != null)
       {
          $c->addAnd(JobsPeer::JOB,$job);
       }  
       if($programming_language != null)
       {
          $c->addAnd(JobsPeer::LANGUAGE,$programming_language);
       }
       $jobs=JobsPeer::doSelect($c);
       return $jobs;
    }
    

    It works for now but i dont know its a good logic or not....

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题