亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

有沒有辦法刪除傳輸到另一個選項卡的數據?避免同一頁面重復?PHP 代碼點火器

有沒有辦法刪除傳輸到另一個選項卡的數據?避免同一頁面重復?PHP 代碼點火器

PHP
拉丁的傳說 2023-07-01 10:13:09
我正在創建一個測驗應用程序,所以概念是當測驗提交并成功評分時,它將移至我已成功完成的第一個選項卡中,但問題是第二個選項卡,即我的測驗名稱已回答仍然可見,如何將其刪除或在回答考試后使其消失。到目前為止,我已經使用它來刪除,但問題是在我回答活動后,只有第一個索引從第二個選項卡中刪除。第一個選項卡 - 這是考試的結果<?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)
查看完整描述

1 回答

?
湖上湖

TA貢獻2003條經驗 獲得超2個贊

在第一個選項卡代碼中循環遍歷 $results 時,您退出循環并為 $res 分配一個值,該值在第二個選項卡代碼中不會更改。這就是為什么第二個選項卡中只排除一個索引的原因。要解決此問題,請將 $post 與 $results 中存儲的所有值進行比較。


如果您的 $results 數組包含所有已回答的測驗,您可以在循環 $posts 時使用 in_array 檢查 $results 是否包含 $post 的值。這是示例代碼:


if (!in_array($post, $results)) { //search in $results for $post

   // Show the Quiz since it has not been answered

}

我建議創建一個新數組,在第一個選項卡的循環中保存 $res 的每個新值,并使用上面相同的邏輯。


第一個選項卡的新代碼


<?php $newArray = array();

      foreach($results as $result):

      $res = $result['activity'];

      array_push($newArray, $res) ?>

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

<?php endforeach; ?>

第二個選項卡的新代碼


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

      $pos = $post['activity']; 

      if (!in_array($pos, $newArray)): ?>

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

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

      </a>

      <?php endif; ?>

<?php endforeach; ?>


查看完整回答
反對 回復 2023-07-01
  • 1 回答
  • 0 關注
  • 123 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號