php - codeigniter 下拉顺序,在第一个下拉菜单中选择的值不得出现在第二个下拉菜单中

标签 php javascript mysql codeigniter

我需要在健身房设置一个四顺序选择运动,所以我必须使用四个下拉菜单,我已经从数据库中检索数据列表,当我选择第一个时,它是一个包含 30 个学科的数组 drom 数据库在第一个下拉菜单中,第二个下拉菜单不能包含这个值,而且当我从第三个下拉菜单中选择一个值时,这个下拉菜单不能包含来自 dropdown1 和 dropdown2 的 value1 和 value2,同样关于下拉菜单 4 它必须只包含来自数据库的 27 个值

我的模型:participantsport_m.php:

  public function get_new()

{

$participant_sport = new stdClass();

$participant_sport->nom = '';
$participant_sport->prenom = '';
$participant_sport->trimestres = '';
$participant_sport->sport_ordre1 = '';
$participant_sport->sport_ordre2 = '';
$participant_sport->sport_ordre3 = '';
$participant_sport->sport_ordre4 = '';
$participant_sport->sport_montant_paye = '';
$participant_sport->sport_debut_periode = '';
$participant_sport->sport_fin_periode = '';
  return $participant_sport;
}


    function get_discipline_sport() {
            $this ->db->select('id, nom_discipline');
            $query = $this ->db->get('disciplines_sport');

            $salles = array();

            if ($query->result()) {
                    foreach ($query->result() as $discipline) {
                      $disciplines[$discipline->id] = $discipline->nom_discipline;
                    }
                    return $disciplines;
            } else {
                    return FALSE;
            }
    }

数据库结构: id - nom_discipline - tarif_discipline - 描述

我的 Controller agent.php :

        public function inscriresport ($id = NULL)
        {

            // Fetch a participant or set a new one
            if ($id) {
                $this->data['participant_sport'] = $this->participantsport_m->get($id);
                count($this->data['participant_sport']) || $this->data['errors'][] = 'Agent non trouvé';

            // explode to array
            // print_r($this->data['participant_sport']['trimestres[]']); // test before explode

              $this->data['participant_sport']->trimestres = explode(",", $this->data['participant_sport']->trimestres);

            // print_r($this->data['participant_sport']['trimestres[]']); // test after explode
            }
            else {
                $this->data['participant_sport'] = $this->participantsport_m->get_new();
            }

            // Set up the form
            $rules = $this->participantsport_m->rules_participantsport;
            $this->form_validation->set_rules($rules);

            // Process the form

            if ($this->form_validation->run() == TRUE) {
                $data = $this->participantsport_m->array_from_post(array('nom', 'prenom', 'beneficiaire', 'trimestres' , 'sport_ordre1', 'sport_ordre2', 'sport_ordre3', 'sport_ordre3',  ,'sport_montant_paye', 'sport_debut_periode', 'sport_fin_periode'));
                $this->participantsport_m->save($data, $id);
                redirect('admin/agent/profile/3608');
            }

            // Load the view
            $this->data['subview'] = 'admin/agent/inscriresport';
            $this->load->view('admin/_layout_main', $this->data);
       }

我的观点是 inscriresport.php :

                    <div class="widget-box">
                        <div class="widget-title">
                            <span class="icon">
                                <i class="icon-align-justify"></i>                                  
                            </span>
                            <h5><?php echo empty($participant->id) ? 'Nouveau Agent OCP:' : 'Modification de: ' . $participant_sport->nom.' '.$participant_sport->prenom; ?></h5>
                        </div>

                        <div class="widget-content nopadding">

                            <?php echo form_open(); ?>



                  <div  <?php if(form_error('nom')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
                    <label class="control-label">Nom :</label>
                    <div class="controls">
                       <?php echo form_input('nom', set_value('nom', $this->input->get('nom') )); ?>
                       <span class="help-inline"><?php echo form_error('nom'); ?></span>
                    </div>
                  </div>


                  <div  <?php if(form_error('prenom')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
                    <label class="control-label">Prenom :</label>
                    <div class="controls">
                       <?php echo form_input('prenom', set_value('prenom', $this->input->get('prenom') )); ?>
                       <span class="help-inline"><?php echo form_error('prenom'); ?></span>
                    </div>
                  </div>




                        <div  <?php if(form_error('beneficiaire')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
                          <label class="control-label">Bénéficiaire :</label>
                          <div class="controls">

                                                  <label><?php echo form_radio('beneficiaire', 'Agent', $this->input->get('beneficiaire') == 'Agent') ?> Agent </label>

                                                  <label><?php echo form_radio('beneficiaire', 'Conjoint', $this->input->get('beneficiaire')  == 'Conjoint') ?> Conjoint </label>

                                                  <label><?php echo form_radio('beneficiaire', 'Enfant', $this->input->get('beneficiaire')  == 'Enfant') ?> Enfant </label>
                                                  <span class="help-inline"><?php echo form_error('beneficiaire'); ?></span>
                          </div>
                        </div>




              <div <?php if(form_error('trimestres[]')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
                      <label class="control-label">Trimestres :</label>
                      <div class="controls" >

                      <?php $options = array(
                                          'trim1'  => ' Premier trimestre (Janv,Fév,Mars)',
                                          'trim2'    => ' Deuxiéme trimestre (Avril,Mai,Juin)',
                                          'trim3'   => ' Troisiéme trimestre (Juill,Aout,Sept)',
                                          'trim4' => ' Quatriéme trimestre (Oct,Nov,Déc)',
                                        );
                     echo form_multiselect('trimestres[]', $options , $this->input->post('trimestres') ? $this->input->post('trimestres') : $participant_sport->trimestres, 'id="trim"'); ?>
                      <span class="help-inline"><?php echo form_error('trimestres[]'); ?></span>
                  </div>
              </div>


              <div <?php if(form_error('sport_ordre1')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
                      <label class="control-label">Nom de la Salle :</label>
                      <div class="controls">
                      <?php echo form_dropdown('sport_ordre1', $countries , $this->input->post('sport_ordre1') ? $this->input->post('sport_ordre1') : $participant_salle->sport_ordre1 , 'id="ordre1"'); ?>
                      <span class="help-inline"><?php echo form_error('sport_ordre1'); ?></span>
                  </div>
              </div>

              <div <?php if(form_error('sport_ordre2')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
                      <label class="control-label">Nom de la Salle :</label>
                      <div class="controls">
                      <?php echo form_dropdown('sport_ordre2', $countries , $this->input->post('sport_ordre2') ? $this->input->post('sport_ordre2') : $participant_salle->sport_ordre2 , 'id="ordre2"'); ?>
                      <span class="help-inline"><?php echo form_error('sport_ordre2'); ?></span>
                  </div>
              </div>

              <div <?php if(form_error('sport_ordre3')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
                      <label class="control-label">Nom de la Salle :</label>
                      <div class="controls">
                      <?php echo form_dropdown('sport_ordre3', $countries , $this->input->post('sport_ordre3') ? $this->input->post('sport_ordre3') : $participant_salle->sport_ordre3 , 'id="ordre3"'); ?>
                      <span class="help-inline"><?php echo form_error('sport_ordre3'); ?></span>
                  </div>
              </div>

              <div <?php if(form_error('sport_ordre4')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
                      <label class="control-label">Nom de la Salle :</label>
                      <div class="controls">
                      <?php echo form_dropdown('sport_ordre4', $countries , $this->input->post('sport_ordre4') ? $this->input->post('sport_ordre4') : $participant_salle->sport_ordre4 , 'id="ordre4"'); ?>
                      <span class="help-inline"><?php echo form_error('sport_ordre4'); ?></span>
                  </div>
              </div>




                        <div  <?php if(form_error('sport_montant_paye')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
                          <label class="control-label">Montant à payé :</label>
                          <div class="controls">
                             <?php echo form_input('sport_montant_paye', set_value('sport_montant_paye', $participant_sport->sport_montant_paye)); ?>
                             <span class="help-inline"><?php echo form_error('sport_montant_paye'); ?></span>
                          </div>
                        </div>






                        <div  <?php if(form_error('sport_debut_periode')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
                          <label class="control-label">Debut période :</label>
                          <div class="controls">
                             <input type="text" name="sport_debut_periode" id="date3" value="<?php echo set_value('sport_debut_periode', $participant_sport->sport_debut_periode) ?>" />
                             <span class="help-inline"><?php echo form_error('sport_debut_periode'); ?></span>
                          </div>
                        </div>




                        <div  <?php if(form_error('sport_fin_periode')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
                          <label class="control-label">Fin période :</label>
                          <div class="controls">
                             <input type="text" name="sport_fin_periode" id="date4" value="<?php echo set_value('sport_fin_periode', $participant_sport->sport_fin_periode) ?>" />
                             <span class="help-inline"><?php echo form_error('sport_fin_periode'); ?></span>
                          </div>
                        </div>






                                <div class="form-actions">
                                    <?php echo form_submit('submit', 'Enregistrer', 'class="btn btn-success"'); ?>
                                </div>
                            <?php echo form_close();?>

                        </div>
                    </div>

                </br>

我需要如何通过 javascript 来完成我是 javascript 的新手,我不知道我从哪里开始,有什么帮助吗?非常感谢。

最佳答案

我建议在所有下拉菜单中包含所有运动,当您想提交表单时,去检查是否有相同值的下拉菜单。您可以通过以下方式获得它们:

var flag = false;

var e1 = document.getElementById("dropdown1 id");
var value1 = e1.options[e1.selectedIndex].value;

var e2 = document.getElementById("dropdown2 id");
var value2 = e2.options[e2.selectedIndex].value;

...

if(value1 != value2 && ...)
{
  flag = true;
}

if(flag)
{
  // Stuff
}

关于php - codeigniter 下拉顺序,在第一个下拉菜单中选择的值不得出现在第二个下拉菜单中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17534390/

相关文章:

mysql - 查找连续记录的数量

php - Echo Count 输出 PHP, PostGres

javascript - jquery自动完成从本地文件获取数据

Javascript 下载在 Firefox 和 IE 中不起作用

javascript - 可以使用 hammer.js 平移事件并仍然允许用户滚动吗?

php - 错误 : Join in MySql, PHP

php - HTTP 500 错误但确实将数据存储到数据库 - Wordpress new-post.php、post.php、edit-post.php 在更新数据结构和插件后无法正常工作

php - 如何判断Web应用程序是否已经安装和设置?

javascript - 为什么jquery加载大量数据时浏览器会阻塞?

php - 根据用户偏好查找特定记录