猿问

有没有办法删除传输到另一个选项卡的数据?避免同一页面重复?PHP 代码点火器

我正在创建一个测验应用程序,所以概念是当测验提交并成功评分时,它将移至我已成功完成的第一个选项卡中,但问题是第二个选项卡,即我的测验名称已回答仍然可见,如何将其删除或在回答考试后使其消失。

到目前为止,我已经使用它来删除,但问题是在我回答活动后,只有第一个索引从第二个选项卡中删除。

第一个选项卡 - 这是考试的结果


<?php foreach($results as $result): ?>

    <?php 

     $res = $result['activity'];  ?>

    

    <h4><?php echo $result['activity']; ?></h4>


<?php endforeach; ?>

这是第二个选项卡,显示所有未回答的考试


<?php foreach($posts as $post): ?>

    <?php

        $pos = $post['activity'];  ?>

    <?php if($res != $post): ?>

    //So by comparing it if it is compared then the name must be removed

                        

        <a href="<?php echo base_url() ?>activity/start/<?php echo $post['id']; ?>/<?php echo $id; ?>"> 

            <?php echo $post['activity']; ?> 

        </a>

                                        

                                                        

        <?php endif; ?>

    <?php endforeach; ?>

    ?>

查看所有已发布考试的模型


public function class_posts($id){

    $this->db->select('*'); 

    $this->db->from('posts');

    $this->db->where('posts.teacher_id', $id);

    $query = $this->db->get();

    return $result = $query->result_array();

}

考试结果模型以及考试后查看。


public function class_groups($id){

    $this->db->select('*');

    $this->db->from('posts');

    $this->db->join('results', 'results.post_id  = posts.id');

    $this->db->where('class_id', $id);

    $this->db->where('student_id', $this->session->userdata('user_id'));

    $this->db->group_by('posts.activity');

    $query = $this->db->get();

    return $result = $query->result_array();

}

var_dump($post)

http://img4.mukewang.com/649fb2af0001a2a911370889.jpg

拉丁的传说
浏览 102回答 1
1回答

湖上湖

在第一个选项卡代码中循环遍历 $results 时,您退出循环并为 $res 分配一个值,该值在第二个选项卡代码中不会更改。这就是为什么第二个选项卡中只排除一个索引的原因。要解决此问题,请将 $post 与 $results 中存储的所有值进行比较。如果您的 $results 数组包含所有已回答的测验,您可以在循环 $posts 时使用 in_array 检查 $results 是否包含 $post 的值。这是示例代码:if (!in_array($post, $results)) { //search in $results for $post&nbsp; &nbsp;// Show the Quiz since it has not been answered}我建议创建一个新数组,在第一个选项卡的循环中保存 $res 的每个新值,并使用上面相同的逻辑。第一个选项卡的新代码<?php $newArray = array();&nbsp; &nbsp; &nbsp; foreach($results as $result):&nbsp; &nbsp; &nbsp; $res = $result['activity'];&nbsp; &nbsp; &nbsp; array_push($newArray, $res) ?>&nbsp; &nbsp; &nbsp; <h4><?php echo $result['activity']; ?></h4><?php endforeach; ?>第二个选项卡的新代码<?php foreach($posts as $post):&nbsp;&nbsp; &nbsp; &nbsp; $pos = $post['activity'];&nbsp;&nbsp; &nbsp; &nbsp; if (!in_array($pos, $newArray)): ?>&nbsp; &nbsp; &nbsp; <a href="<?php echo base_url();?>activity/start/<?php echo $post['id'];?>/<?php echo $id;?>">&nbsp;&nbsp; &nbsp; &nbsp; <?php echo $post['activity']; ?>&nbsp;&nbsp; &nbsp; &nbsp; </a>&nbsp; &nbsp; &nbsp; <?php endif; ?><?php endforeach; ?>
随时随地看视频慕课网APP
我要回答