最后一项是未从数据库中删除的选择列表

时间:2018-11-20 20:34:56

标签: php moodle

我目前有一个选择列表,其功能几乎完美。我遇到的问题是,当所有先前选择的项目都未选择并且提交表单时,单个项目仍然保持选中状态。为什么会这样呢?为了取消选中所有项目,我需要对代码进行哪些更改。提前致谢!我的代码如下:

$domain_records = $DB->get_records('tag', ['tagtype' => 'domain'], $sort = 'rawname', '*');
if(!empty($_POST["domain_list"]) || isset($_POST["domain_list"])){

$posted_domains = $_POST["domain_list"];
 // elseif logic submits newly selected tags

 foreach($domain_records as $domain_record) {
     // already selected and still selected
     if(in_array($domain_record->id, $posted_domains) === true && 
        $DB->record_exists('table name', array('journal_publication_id' => $pubid, 'tag_id' => $domain_record->id))) {
             continue;
     }
     // selected and no longer selected on post
     else if(in_array($domain_record->id, $posted_domains) === false && 
        $DB->record_exists('tcors_journal_tags_matrix', array('table name' => $pubid, 'tag_id' => $domain_record->id))) {
         // DELETE ME!!!!
         $DB->delete_records("table name", array('journal_publication_id' => $pubid, 'tag_id' => $domain_record->id));
     }

     }
     else if(in_array($domain_record->id, $posted_domains) === true) {
         //submit values into db

     }

 }
} 

0 个答案:

没有答案
相关问题