2017-04-10 39 views
0

我使用PHP的CodeIgniter,我想張貼錶行,並獲得在控制器中的職位值,控制器工作正常,但我無法發佈值。PHP的CodeIgniter不張貼錶行數據

我創建它的控制器成功的唯一的部分是值沒有得到張貼。

我想發佈表中的一行,而不是所有的行的值。

這裏是我的表單代碼

<div class="row" id="attendance_list"> 
    <div class="col-sm-offset-3 col-md-6"> 
     <table class="table table-bordered"> 

      <thead> 
       <tr> 
        <td><?php echo get_phrase('student_id');?></td> 
        <td><?php echo get_phrase('roll');?></td> 
        <td><?php echo get_phrase('name');?></td> 
        <td><?php echo get_phrase('Theory');?></td> 
        <td><?php echo get_phrase('Practical');?></td> 
        <td><?php echo get_phrase('Send Remarks');?></td> 
        <td><?php echo get_phrase('SEND');?></td> 
       </tr> 
      </thead> 
      <tbody> 

       <?php echo form_open(base_url() . 'index.php?admin/send_message_to_perent/create' , array('class' => 'form-horizontal form-groups-bordered validate','target'=>'_top'));?> 


       <?php 
        $students = $this->db->get_where('student' , array('class_id'=>$class_id))->result_array(); 
         foreach($students as $row): 


         <tr class="gradeA"> 

          <td> 

          <input type="hidden" name="student_id" value="<?php echo $row['student_id'];?>"> 
          <?php echo $row['student_id'];?> 


          </td> 


          <td> 
          <?php echo $row['roll'];?>      

          </td> 

          <td><?php echo $row['name'];?></td> 


       <!-- For Theory Attendance--> 



          <td> 

          <?php echo number_format((float)$theoryPercentage, 0, '.', ''); ?> % 

          </td>  





       <!-- For Practical Attendance--> 



          <td> <?php echo number_format((float)$practicalPercentage, 0, '.', ''); ?> % </td> 



        <td> 

          <input type="textarea" name="notice" value="<?php echo $row['notice'];?>"> 




        </td> 

       <td> 

         <div class="form-group"> 
          <div class="col-sm-offset-3 col-sm-5"> 
           <button type="submit" class="btn btn-info"><?php echo get_phrase('SEND');?></button> 
          </div> 
         </div> 



       </td> 


         </tr> 
        <?php endforeach;?> 



      </form>   
      </tbody> 

     </table> 
    </div> 
</div> 
+0

您在打開表格時錯過了方法=「POST」。 –

+0

我也試過,但它不起作用 – AndroidHacker

+0

是你的動作網址好嗎? –

回答

2

有幾件事情錯。由於Codeigniter是一個MVC框架,您應該遵循它的標準。 https://softwareengineering.stackexchange.com/questions/127624/what-is-mvc-really

值得注意的是,這不應該在視圖內進行數據庫調用。數據庫調用應位於模塊中,並從控制器傳遞到視圖。

其他項目: 忘了關閉>foreach ($students as $row) : 這是一個無效的輸入型<input type="textarea"

我真的不完全理解這個問題後,我不知道,如果你想爲一種新的形式?每行都有自己的提交按鈕,您需要一個帶有一個提交按鈕的大表單。

我給的答案是假設你想要一個帶有一個提交按鈕的大表單。

<?php echo form_open(base_url() . 'index.php?admin/send_message_to_perent/create' , array('class' => 'form-horizontal form-groups-bordered validate','target'=>'_top'));?> 
<?php 
foreach ($students as $row) : 
?> 
     <tr class="gradeA"> 
      <td> 
      <input type="hidden" name="student_id[]" value="<?php echo $row['student_id'];?>"> 
      <?php echo $row['student_id']; ?> 
      </td> 
      <td><?php echo $row['roll'];?>      
      </td> 
      <td><?php echo $row['name'];?></td> 
<!-- For Theory Attendance--> 
<td><?php echo number_format((float)$theoryPercentage, 0, '.', ''); ?> % 
</td> 
<!-- For Practical Attendance--> 
<td> <?php echo number_format((float)$practicalPercentage, 0, '.', ''); ?> % </td> 
<td><textarea rows="4" cols="50" name="notice[]"><?php echo $row['notice'];?></textarea></td> 

</tr> 
<?php endforeach;?> 
<tr><td colspan="5"><div class="form-group"> 
     <div class="col-sm-offset-3 col-sm-5"> 
      <button type="submit" class="btn btn-info"><?php echo get_phrase('SEND');?></button> 
     </div> 
    </div> 
    </td> 
</tr> 
</form> 

下面是每行的表格。

<?php 
foreach ($students as $row) : 
?> 
<?php echo form_open(base_url() . 'index.php? 
    admin/send_message_to_perent/create' , 
array('class' => 'form-horizontal form-groups-bordered validate','target'=>'_top'));?> 
<tr class="gradeA"> 
    <td> 
     <input type="hidden" name="student_id" value="<?php echo $row['student_id'];?>"> 
     <?php echo $row['student_id']; ?> 
    </td> 
    <td><?php echo $row['roll'];?></td> 
    <td><?php echo $row['name'];?></td> 
    <!-- For Theory Attendance--> 
    <td><?php echo number_format((float)$theoryPercentage, 0, '.', ''); ?> % </td> 
    <!-- For Practical Attendance--> 
    <td> <?php echo number_format((float)$practicalPercentage, 0, '.', ''); ?> % </td> 
    <td><textarea rows="4" cols="50" name="notice"><?php echo $row['notice'];?></textarea></td> 
</tr> 
<tr><td colspan="5"> 
    <div class="form-group"> 
     <div class="col-sm-offset-3 col-sm-5"> 
      <button type="submit" class="btn btn-info"><?php echo get_phrase('SEND');?></button> 
     </div> 
    </div> 
    </td> 
</tr> 
</form> 
<?php endforeach;?> 
+0

這個發佈數據,但我想發佈特定行中的值而不是所有行的值。 – AndroidHacker

+0

你能告訴我如何發佈單行的值。 – AndroidHacker

+0

OK - 那麼每一行都是它自己的形式,並且您不需要使用數組標記作爲輸入值。 – Johnish