dongzaliang4492 2018-12-04 19:11
浏览 67

选择不从数据库中删除的列表项

I currently have a multi select box which functions properly until there is one last item which does not delete from the database when deselected. For some reason all but 1 item is removed.

$domain_records = $DB->get_records('tag', ['tagtype' => 'domain'], $sort = 'rawname', '*');

if(!empty($_POST["domain_list"]) || isset($_POST["domain_list"])){
$posted_domains = array();
$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('tcors_journal_tags_matrix', 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('journal_publication_id' => $pubid, 'tag_id' => $domain_record->id))) {
         // DELETE ME!!!!
         $DB->delete_records("tcors_journal_tags_matrix", array('journal_publication_id' => $pubid, 'tag_id' => $domain_record->id));
     }
     else if(empty($posted_domains)){
        $DB->delete_records("tcors_journal_tags_matrix", array('journal_publication_id' => $pubid, 'tag_domain' => "Domain"));
        //$DB->delete_records("tcors_journal_tags_matrix", array('journal_publication_id' => $pubid, 'tag_id' => $domain_record->id));

     }
     else if(in_array($domain_record->id, $posted_domains) === true) {
         $tag_matrix = new \stdClass();
         $tag_matrix->journal_publication_id = $pubid;
         $tag_matrix->tag_id = $domain_record->id;
         $tag_matrix->tag_domain = 'Domain';

         $tag_matrix->create_date = time();
         $tag_matrix->create_by = $USER->id;
         $tag_matrix->modify_date = time();
         $tag_matrix->modify_by = $USER->id;

         $DB->insert_record('tcors_journal_tags_matrix', $tag_matrix);

     }

 }

}

My attempt to account for a scenario where the $posted_domains array (which contains the values to be submitted to the db) is the 2nd to last else if statement. I would like all items deleted when the post back array ($posted_domains) contains no values.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用