找到你要的答案

Q:I have a multiple option select which populate data from MySQL but select first element from html. I do not want to store first element in db

Q:我有一个多选项选择填充数据从MySQL但选择第一个元素的HTML。我不想在数据库中存储第一个元素

This is the html form multiple select list. list option are populated from database. But when I submit the form it also stores <option value="0">Select multiple options:</option> if I select it. I just want that either it is selected or not it should not be stored in db. Thanks in advance.

<p>
  <label for="stu_courses">Courses:</label>
  <br/>
  <select id="stu_courses" name="stu_courses[]" multiple="multiple">
    <option value="0">Select multiple options:</option>

  </select>
</p>

function setdbSelect() {
        $result1 = Plusql::from($this->profile)->courses->select('*')->run()->courses;
        foreach ($result1 as $value){
        echo $result1->course_id;
        }
        $options = array();
        foreach ($result1 as $value) {
            //$this->template->setValue('#stu_courses', $result1->course_name);
            $options[$result1->course_id] = $result1->course_name;            
        }
        
            \Config\Central::repeat_select_options($this->template, "#stu_courses", $options, 0);
        
    }

这是HTML形式多选择列表。列表选项从数据库中填充。但当我提交它还存储& lt形式;期权价值=“0”& gt;选择多个选项:<;/选项>;如果我选择它。我只是希望它是不是选择它不应该存储在DB。先谢谢了。

<p>
  <label for="stu_courses">Courses:</label>
  <br/>
  <select id="stu_courses" name="stu_courses[]" multiple="multiple">
    <option value="0">Select multiple options:</option>

  </select>
</p>

function setdbSelect() {
        $result1 = Plusql::from($this->profile)->courses->select('*')->run()->courses;
        foreach ($result1 as $value){
        echo $result1->course_id;
        }
        $options = array();
        foreach ($result1 as $value) {
            //$this->template->setValue('#stu_courses', $result1->course_name);
            $options[$result1->course_id] = $result1->course_name;            
        }
        
            \Config\Central::repeat_select_options($this->template, "#stu_courses", $options, 0);
        
    }
php  html  mysql  sql