zoukankan      html  css  js  c++  java
  • 编程是要偷懒的--option简练写法

    没改前:

      1 if(!empty($search)){
      2             $where['personal_name'] = array('like','%'. $search . '%');
      3             $this -> assign('search',$search);
      4         }
      5         if(!empty($category)){
      6             if($category == "请选择职位") $category=null;
      7             $where['category_name'] = array('like','%'. $category . '%');
      8 //          $where['category_name'] =  $category;
      9             $this -> assign('category',$category);
     10         }
     11         if(!empty($type)){
     12                 switch ($type){
     13                     case "请选择简历类型":
     14                     $type = null;
     15                     break;    
     16                     case "全职":
     17                     $where['resume_type'] = 1;
     18                     break;         
     19                     case "兼职":
     20                     $where['resume_type'] = 2;
     21                     break;  
     22                     default:break;              
     23                 }
     24             $this -> assign('type',$type);
     25         }
     26         if(!empty($education)){
     27                 switch($education){
     28                     case "请选择个人学历":
     29 //                    $education = null;
     30                     break;
     31                     case "不限":
     32 //                    $where['personal_education'] = 0;
     33                     break;
     34                     case "初中及以下":
     35                     $where['personal_education'] = 1;
     36                     break;
     37                     case "高中":
     38                     $where['personal_education'] = 2;
     39                     break;
     40                     case "中技/中专":
     41                     $where['personal_education'] = 3;
     42                     break;
     43                     case "大专":
     44                     $where['personal_education'] = 4;
     45                     break;
     46                     case "本科":
     47                     $where['personal_education'] = 5;
     48                     break;
     49                     case "硕士":
     50                     $where['personal_education'] = 6;
     51                     break;
     52                     case "MBA/EMBA":
     53                     $where['personal_education'] = 7;
     54                     break;
     55                     case "博士":
     56                     $where['personal_education'] = 8;
     57                     break;
     58                     case "博士后":
     59                     $where['personal_education'] = 9;
     60                     break;
     61                     default:break;  
     62                 }
     63             $this -> assign('education',$education);
     64         }
     65         if(!empty($working)){
     66             switch($working){
     67                 case "请选择个人工作年限":
     68 //              $where['personal_working'] = 0;
     69                 break;
     70                 case "不限":
     71 //              $where['personal_working'] = 0;
     72                 break;
     73                 case "1年以下":
     74                 $where['personal_working'] = 1;
     75                 break;
     76                 case "1-2年":
     77                 $where['personal_working'] = 2;
     78                 break;
     79                 case "3-5年":
     80                 $where['personal_working'] = 3;
     81                 break;
     82                 case "6-7年":
     83                 $where['personal_working'] = 4;
     84                 break;
     85                 case "8-10年":
     86                 $where['personal_working'] = 5;
     87                 break;
     88                 case "10年以上":
     89                 $where['personal_working'] = 6;
     90                 break;
     91                 default:break; 
     92             }
     93             $this -> assign('working',$working);
     94         }
     95         if(!empty($sex)){
     96              switch($sex){
     97                  case "不限":
     98                  //
     99                  break;
    100                  case "男":
    101                  $where['personal_sex'] = 1;
    102                  break;
    103                  case "女":
    104                  $where['personal_sex'] = 2;
    105                  break;
    106                  default: break;
    107              }
    108              $this -> assign('sex',$sex);
    109         }

    html:

     1         <form method="get">
     2            <select class="button text" style="background-color: white; color: #428bca;" name="category">
     3                   <option>请选择职位</option>
     4                   <foreach name='select_name' item='v' >
     5                        <option <if condition="($category eq $v[category_name])">selected="selected"</if> >{$v.category_name}</option>
     6                   </foreach>
     7            </select>
     8            <select class="button text" style="background-color: white; color: #428bca;" name="type">
     9                   <option>请选择简历类型</option>
    10                   <option <if condition="($type eq 全职)">selected="selected"</if> > 全职</option>
    11                   <option <if condition="($type eq 兼职)">selected="selected"</if> >兼职</option>
    12            </select>
    13            <select class="button text" style="background-color: white; color: #428bca;" name="education">
    14                   <option>请选择个人学历</option>
    15                   <option  <if condition="($education eq 不限)">selected="selected"</if> >不限</option>
    16                   <option  <if condition="($education eq 初中及以下)">selected="selected"</if> >初中及以下</option>
    17                   <option  <if condition="($education eq 高中)">selected="selected"</if> >高中</option>
    18                   <option  <if condition="($education eq '中技/中专')">selected="selected"</if> >中技/中专</option>
    19                   <option  <if condition="($education eq 大专)">selected="selected"</if> >大专</option>
    20                   <option  <if condition="($education eq 本科)">selected="selected"</if> >本科</option>
    21                   <option  <if condition="($education eq 硕士)">selected="selected"</if> >硕士</option>
    22                   <option  <if condition="($education eq MBA)">selected="selected"</if> >MBA/EMBA</option>
    23                   <option  <if condition="($education eq 博士)">selected="selected"</if> >博士</option>
    24                   <option  <if condition="($education eq 博士后)">selected="selected"</if> >博士后</option>
    25            </select>
    26            <select class="button text" style="background-color: white; color: #428bca;" name="working">
    27                   <option>请选择个人工作年限</option>
    28                   <option  <if condition="($working eq 不限)">selected="selected"</if> >不限</option>
    29                   <option  <if condition="($working eq '1年以下')">selected="selected"</if> >1年以下</option>
    30                   <option  <if condition="($working eq '1-2年')">selected="selected"</if> >1-2年</option>
    31                   <option  <if condition="($working eq '3-5年')">selected="selected"</if> >3-5年</option>
    32                   <option  <if condition="($working eq '6-7年')">selected="selected"</if> >6-7年</option>
    33                   <option  <if condition="($working eq '8-10年')">selected="selected"</if> >8-10年</option>
    34                   <option  <if condition="($working eq '10年以上')">selected="selected"</if> >10年以上</option>
    35            </select>
    36            <select class="button text" style="background-color: white; color: #428bca;" name="sex">
    37                   <option>请选择性别</option>
    38                   <option <if condition="($sex eq 不限)">selected="selected"</if> >不限</option>
    39                   <option <if condition="($sex eq 男)">selected="selected"</if> >男</option>
    40                   <option <if condition="($sex eq 女)">selected="selected"</if> >女</option>
    41            </select>
    42            <div class="btn-group"></div>
    43            <input type="text" class="search" placeholder="请输入个人姓名" name="search" value="{$search}" style="margin-left: 1%;"/>         
    44            <input type="submit" value="搜索" class=" text button" style="border: none;  float: none; margin-left: 1%;" />
    45         </form>

    修改后:

    $type_array = array("请选择简历类型","全职","兼职");
            $education_array = array("请选择个人学历","不限","初中及以下","高中","中技/中专","大专","本科","硕士","MBA/EMBA","博士","博士后");
            $working_array = array("请选择个人工作年限","不限","1年以下","1-2年","3-5年","6-7年","8-10年","10年以上");
            $sex_array = array("不限","男","女");
            
            
            if(!empty($search)){
                $where['personal_name'] = array('like','%'. $search . '%');
                $this -> assign('search',$search);
            }
            if(!empty($category)){
                if($category == "请选择职位") $category=null;
                $where['category_name'] = array('like','%'. $category . '%');
                $this -> assign('category',$category);
            }
            if(!empty($type)){
                    switch ($type){
                        case $type_array[0]:
                        $type = null;
                        break;    
                        case $type_array[1]:
                        $where['resume_type'] = 1;
                        break;         
                        case $type_array[2]:
                        $where['resume_type'] = 2;
                        break;  
                        default:break;              
                    }
                $this -> assign('type',$type);
            }
            if(!empty($education)){
                    switch($education){
                        case $education_array[0]:
    //                    $education = null;
                        break;
                        case $education_array[1]:
    //                    $where['personal_education'] = 0;
                        break;
                        case $education_array[2]:
                        $where['personal_education'] = 1;
                        break;
                        case $education_array[3]:
                        $where['personal_education'] = 2;
                        break;
                        case $education_array[4]:
                        $where['personal_education'] = 3;
                        break;
                        case $education_array[5]:
                        $where['personal_education'] = 4;
                        break;
                        case $education_array[6]:
                        $where['personal_education'] = 5;
                        break;
                        case $education_array[7]:
                        $where['personal_education'] = 6;
                        break;
                        case $education_array[8]:
                        $where['personal_education'] = 7;
                        break;
                        case $education_array[9]:
                        $where['personal_education'] = 8;
                        break;
                        case $education_array[10]:
                        $where['personal_education'] = 9;
                        break;
                        default:break;  
                    }
                $this -> assign('education',$education);
            }
            if(!empty($working)){
                switch($working){
                    case $working_array[0]:
    //              $where['personal_working'] = 0;
                    break;
                    case $working_array[1]:
    //              $where['personal_working'] = 0;
                    break;
                    case $working_array[2]:
                    $where['personal_working'] = 1;
                    break;
                    case $working_array[3]:
                    $where['personal_working'] = 2;
                    break;
                    case $working_array[4]:
                    $where['personal_working'] = 3;
                    break;
                    case $working_array[5]:
                    $where['personal_working'] = 4;
                    break;
                    case $working_array[6]:
                    $where['personal_working'] = 5;
                    break;
                    case $working_array[7]:
                    $where['personal_working'] = 6;
                    break;
                    default:break; 
                }
                $this -> assign('working',$working);
            }
            if(!empty($sex)){
                 switch($sex){
                     case $sex_array[0]:
                     //
                     break;
                     case $sex_array[1]:
                     $where['personal_sex'] = 1;
                     break;
                     case $sex_array[2]:
                     $where['personal_sex'] = 2;
                     break;
                     default: break;
                 }
                 $this -> assign('sex',$sex);
            }
    
            $this -> assign('type_array',$type_array);
            $this -> assign('education_array',$education_array);
            $this -> assign('working_array',$working_array);
            $this -> assign('sex_array',$sex_array);

    html:

               <select class="button text" style="background-color: white; color: #428bca;" name="category">
                      <option>请选择职位</option>
                      <foreach name='select_name' item='v' >
                           <option <if condition="($category eq $v[category_name])">selected="selected"</if> >{$v.category_name}</option>
                      </foreach>
               </select>
               
               <select class="button text" style="background-color: white; color: #428bca;" name="type">
                      <foreach name='type_array' item='v'>
                            <option <if condition="($type eq $v)">selected="selected"</if> >{$v}</option>
                      </foreach>
               </select>
               
               <select class="button text" style="background-color: white; color: #428bca;" name="education">
                      <foreach name='education_array' item='v'>
                            <option  <if condition="($education eq $v)">selected="selected"</if> >{$v}</option>
                      </foreach>
               </select>
               
               <select class="button text" style="background-color: white; color: #428bca;" name="working">
                       <foreach name="working_array" item="v">
                           <option  <if condition="($working eq $v)">selected="selected"</if> >{$v}</option>
                       </foreach>
               </select>
               
               <select class="button text" style="background-color: white; color: #428bca;" name="sex">
                       <foreach name='sex_array' item='v'>
                           <option <if condition="($sex eq $v)">selected="selected"</if> >{$v}</option>
                       </foreach>
               </select>

    编程是要偷懒的

  • 相关阅读:
    名师破解英语四级汉译英
    名师破解英语四级汉译英
    名师破解英语四级汉译英
    输出矩阵右上角元素
    输入行列式中偶数行和偶数列的数据
    转秩矩阵
    数据排序
    从键盘上输入5个数,输出最大、最小元素的值以及它们的下标
    中文处理(全角/半角)
    获取汉字拼音首字母
  • 原文地址:https://www.cnblogs.com/laijinquan/p/7497492.html
Copyright © 2011-2022 走看看