简体   繁体   English

对于相同的值,for 循环一次又一次地进行

[英]For loop is going again and again for the same values

I am not sure what is going wrong.我不确定出了什么问题。 But the system is printing the same values again and again, where it should echo the value only once where it is matching student_id in the delivery table.但是系统一次又一次地打印相同的值,它应该只在传递表中与 student_id 匹配的地方回显该值一次。 The full code I have edited as requested.我已按要求编辑的完整代码。 This is not executing the query but able display the Table headings.这不是在执行查询,而是能够显示表标题。

The code is:代码是:

    <?php $min = $this->db->get_where('academic_settings' , array('type' =>'minium_mark'))->row()->description;?>
<?php $running_year = $this->db->get_where('settings' , array('type' => 'running_year'))->row()->description; ?>

<div class="content-w">
      <div class="conty">
          <?php include 'fancy.php';?>
          <div class="header-spacer"></div>
     <div class="content-i">
    <div class="content-box">
            <div class="row">   

                                                                                          
                                                    <div class="table-responsive">
                                                    <table width="100%" class="table table-striped table-lightfont">
<tbody>

 
                <tr>
                    <td style="color:black !important; text-transform:uppercase; text-align:center;">
                    <?php echo get_phrase('Subject_Name');?>&nbsp;:&nbsp;
                        <span><?php echo $row['name'];?></span>
                    </td>
                </tr>
                <tr>
                    <td>
                                <table class="table table-padded">
                                <thead style="background-color:#90be2e; color:white;">
                                    <tr style="padding-bottom:4px; padding-top:4px;">
                                <th style="color:white;"><?php echo get_phrase('Publish Date');?></th>
                                <th style="color:white;"><?php echo get_phrase('Assignment');?></th>
                                <th style="color:white;"><?php echo get_phrase('Faculty');?></th>
                                <th style="color:white;"><?php echo get_phrase('Last Date');?></th>
                                <th style="color:white;"><?php echo get_phrase('Submitted On');?></th>
                                <th style="color:white;"><?php echo get_phrase('Marks');?></th>
                                <th style="color:white;"><?php echo get_phrase('Feedback');?></th>
                                    </tr>
                                </thead>
                            <tbody>
                            
<?php 
     $uploader_id_student = $this->db->get_where('student', array('student_id' => $this->session->userdata('login_user_id')))->row()->student_id;
     $invoices = $this->db->get_where('deliveries', array('student_id' => $uploader_id_student))->result_array(); 
                
                foreach($invoices as $row2): 
 ?> 
                    <tr>
                        <td>
                            <?php echo $this->db->get_where('homework' , array('homework_code'=>$row2['homework_code']))->row()->upload_date;?> 
                        </td> 
                        <td>
                            <?php 
                                $get_homework_data = $this->db->get_where('homework' , array('homework_code'=>$row2['homework_code']))->row();
                                echo wordwrap($get_homework_data->title,15,"<br>\n");
                               ?>
                        </td>
                        <td>
                            <?php 
                                echo $this->db->get_where('teacher' , array('teacher_id'=>$get_homework_data->uploader_id))->row()->first_name;
                            ?>&nbsp; 
                            <?php 
                                echo $this->db->get_where('teacher' , array('teacher_id'=>$get_homework_data->uploader_id))->row()->last_name;
                             ?>                         
                        </td>
                        <td>
                            <?php 
                                $sampleDate1 = $this->db->get_where('homework' , array('homework_code'=>$row2['homework_code']))->row()->date_end;
                                $convertDate1 = date("d-m-Y", strtotime($sampleDate1));
                                echo $convertDate1;

                            ?>                          
                         </td>
                         <td>
                            <?php
                                $sampleDate = $row2['date'];
                                $convertDate = date("d-m-Y", strtotime($sampleDate));
                                echo $convertDate;
                            ?>
                        </td> 
                        <td style="text-align:center;">
                            <?php echo $row2['mark'];?>
                        </td> 
                        <td>
                            <?php echo wordwrap($row2['teacher_comment'],25,"<br>\n");?>
                        </td> 

                  </tr>
                            
            <?php endforeach;?>
                                                        
    <!--<?php endforeach;?> -->
                            </tbody>
                            </table>
                </td>
                        
            </tr>               
                                                    </tbody>
                                                </table>

                                         </div>
                                       
                                            </div>
                                            </div>
                                                </div>  
                                            </div>
                                            
                                               
        </div>

attached is screenshot of table Deliveries is there Deliveries Picture Download附件是表格Deliveries的截图有没有Deliveries图片下载

Here is your code updated to fix the performance issues mentioned by Arnold Daniels.这是您更新的代码,以修复 Arnold Daniels 提到的性能问题。

<?php
$uploader_id_student = $this->session->userdata('login_user_id');
$invoices = $this->db->get_where('deliveries', array('student_id' => $uploader_id_student))->result_array(); 
foreach($invoices as $row2) {
  $get_homework_data = $this->db->get_where('homework' , array('homework_code'=>$row2['homework_code']))->row();
  $teacher = $this->db->get_where('teacher' , array('teacher_id'=>$get_homework_data->uploader_id))->row();
?>
  <tr>
    <td>
      <?= $get_homework_data->upload_date ?> 
    </td> 
    <td>
      <?= wordwrap($get_homework_data->title,25,"<br>\n") ?>
    </td>
    <td>
      <?= $teacher->first_name . ' ' . $teacher->last_name ?>
    </td>
</tr>
<?php
}
?>

It appears to be working fine as far as I could test it.据我测试,它似乎工作正常。 Is there anything missing from the snippet you posted that could help reproduce your issue?您发布的代码片段中是否缺少任何有助于重现您的问题的内容?

Edit:编辑:

So the complete code would be:所以完整的代码是:

<?php
$min = $this->db->get_where('academic_settings' , array('type' =>'minium_mark'))->row()->description;
$running_year = $this->db->get_where('settings', array('type' => 'running_year'))->row()->description;
?>
<div class="content-w">
  <div class="conty">
    <?php include 'fancy.php'; ?>
    <div class="header-spacer"></div>
    <div class="content-i">
      <div class="content-box">
        <div class="row">
          <div class="table-responsive">
            <table width="100%" class="table table-striped table-lightfont">
              <tbody>
                <tr>
                  <td style="color:black !important; text-transform:uppercase; text-align:center;">
                    <?php echo get_phrase('Subject_Name'); ?>&nbsp;:&nbsp;
                    <span><?php echo $row['name']; ?></span>
                  </td>
                </tr>
                <tr>
                  <td>
                    <table class="table table-padded">
                      <thead style="background-color:#90be2e; color:white;">
                        <tr style="padding-bottom:4px; padding-top:4px;">
                          <th style="color:white;"><?php echo get_phrase('Publish Date'); ?></th>
                          <th style="color:white;"><?php echo get_phrase('Assignment'); ?></th>
                          <th style="color:white;"><?php echo get_phrase('Faculty'); ?></th>
                          <th style="color:white;"><?php echo get_phrase('Last Date'); ?></th>
                          <th style="color:white;"><?php echo get_phrase('Submitted On'); ?></th>
                          <th style="color:white;"><?php echo get_phrase('Marks'); ?></th>
                          <th style="color:white;"><?php echo get_phrase('Feedback'); ?></th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php
                        $uploader_id_student = $this->db->get_where('student', array('student_id' => $this->session->userdata('login_user_id')))->row()->student_id;
                        $invoices = $this->db->get_where('deliveries', array('student_id' => $uploader_id_student))->result_array();
                        foreach ($invoices as $row2) :
                          $homework_data = $this->db->get_where('homework', array('homework_code' => $row2['homework_code']))->row();
                          $teacher = $this->db->get_where('teacher', array('teacher_id' => $get_homework_data->uploader_id))->row();
                        ?>
                          <tr>
                            <td>
                              <?php echo $homework_data->title->upload_date; ?>
                            </td>
                            <td>
                              <?php
                              echo wordwrap($homework_data->title, 15, "<br>\n");
                              ?>
                            </td>
                            <td>
                              <?php
                              echo $teacher->first_name;
                              ?>&nbsp;
                              <?php
                              echo $teacher->last_name;
                              ?>
                            </td>
                            <td>
                              <?php
                              $sampleDate1 = $homework_data->date_end;
                              $convertDate1 = date("d-m-Y", strtotime($sampleDate1));
                              echo $convertDate1;
                              ?>
                            </td>
                            <td>
                              <?php
                              $sampleDate = $row2['date'];
                              $convertDate = date("d-m-Y", strtotime($sampleDate));
                              echo $convertDate;
                              ?>
                            </td>
                            <td style="text-align:center;">
                              <?php echo $row2['mark']; ?>
                            </td>
                            <td>
                              <?php echo wordwrap($row2['teacher_comment'], 25, "<br>\n"); ?>
                            </td>
                          </tr>
                        <?php endforeach; ?>
                      </tbody>
                    </table>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

I would need to see the contents of the included file "fancy.php" to be sure.我需要查看包含文件“fancy.php”的内容才能确定。 There was an extra endforeach statement, but I'm guessing that it came from somewhere beyond the scope of the snippet you updated.有一个额外的endforeach语句,但我猜它来自您更新的代码段的 scope 之外的某个地方。 I would need to see the whole content of the file and the content of the included script in order to determine the true nature of the error.我需要查看文件的全部内容和包含的脚本的内容,以确定错误的真实性质。

<?--<;php endforeach??> -->

Remove this Line删除此行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM