2015-08-12 3 views
2

Я почесал голову об этом в течение нескольких дней, и я не могу показаться, чтобы понять, почему это не будет работать,модальный и в то время как петля

я модальный, который всплывает при выборе кнопки принять, это модальный следует заселить имя пользователя и номер телефона.

проблема заключается в том, что когда вы выбираете принять его только заполнить первые лица детали и не остальные люди в таблице, я не понимаю, почему, если кто-нибудь может указать, почему я был бы очень благодарен

вот мой код (жаль его ABIT неаккуратна на данный момент):

<?php 

require_once ("includes/session_check.php"); 

require_once ("includes/db_connect.php"); 

//MySqli Select Query 
$results = $mysqli->query("SELECT id, username, phone, requester,goodorbad,confirmed,denied FROM request WHERE goodorbad=1 AND confirmed=0 AND denied=0 Order by ID ASC"); 
echo ' 
     <!-- ********************************************************************************************************************************************************** 
     MAIN CONTENT 
     *********************************************************************************************************************************************************** --> 
     <!--main content start--> 
     <section id="main-content"> 
      <section class="wrapper site-min-height"> 
      <h3><i class="fa fa-angle-right"></i> Non Authenticated Requests</h3> 
      <div class="row mt"> 
       <div class="col-lg-12"> 
       <p>Non Authenticated Requests here.</p>'; 
echo '<div class="row mt"> 
        <div class="col-md-12"> 
         <div class="content-panel"> 
          <table class="table table-striped table-advance table-hover"> 
           <h4><i class="fa fa-angle-right"></i>Non Authenticated Requests</h4> 
           <hr> <thead> 
           <tr> 
            <th><i class="fa fa-bullhorn"></i>Username</th> 
            <th><i class="fa fa-phone"></i>Phone number update request</th> 
            <th><i class="fa fa-bookmark"></i>Requester</th> 
            <th><i class=" fa fa-edit"></i> Status</th> 
            <th><i class=" fa fa-edit"></i> Accept/Decline</th> 
            <th></th> 
           </tr> 
           </thead>'; 


while($row = $results->fetch_object()) { 

    //$row->id 
    //$row->confirmed 
    //$row->denied 

$status = $row->confirmed; 

echo ' 
    <!-- Modal for Confirm --> 

       <form action="#" method="POST"> 
        <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade"> 
         <div class="modal-dialog"> 
          <div class="modal-content"> 
           <div class="modal-header"> 
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
            <input type="hidden" name="username_request" value="'.$row->username.'"/> 
             <input type="hidden" name="telephone_request" value="'.$row->phone.'"/> 
            <h4 class="modal-title">Are you sure ?</h4> 
           </div> 
           <div class="modal-body"> 
            <br> 

            <p>You are about to update </p> 
            '.$row->username.' 
            <br> 
            <p> with the following telephone number </p> 
             '.$row->phone.' 

           <div class="modal-footer"> 
            <button data-dismiss="modal" class="btn btn-default" 
              type="button">Cancel</button> 
            <button data-dismiss="modal" class="btn btn-default" 
              type="button">Submit</button> 

           </div> 
          </div> 
         </div> 
        </div> 
        </form> 
        <!-- modal --> 




           <tbody> 
           <tr> 
            <td><a href="#">'.$row->username.'</a></td> 
            <td>'.$row->phone.'</td> 
            <td>'.$row->requester.' </td>'; 
     if($status == 1){ 


       echo '  <td><span class="label label-success">Completed</span></td> 
         <td></td> 
         <td></td> 
         '; 
     }else{ 

     } 

          echo '<td><span class="label label-info label-mini">Pending</span></td> 

            <td> 
            Accept? 
            <a data-toggle="modal" href="#myModal"> <button class="btn btn-success btn-xs"><i class="fa fa-check"></i></button> 
            </a> 
            <td> 
            Decline? 
             <button class="btn btn-danger btn-xs"><i class="fa fa-minus-circle"></i></button> 
            </td> 
            </td> 


          </tr> 
           </tbody> 





         '; 
} 

echo '  
          </table> 
         </div><!-- /content-panel --> 
        </div><!-- /col-md-12 --> 
       </div><!-- /row -->'; 

// close connection 
$mysqli->close(); 
?> 

<html> 


</html> 
+0

вы должны добавить уникальный ключ в модели. иначе он поймает первый найденный элемент. – MKD

ответ

2

Вам нужно добавить уникальный id каждые model.

Попробуйте

<?php 

require_once ("includes/session_check.php"); 

require_once ("includes/db_connect.php"); 

//MySqli Select Query 
$results = $mysqli->query("SELECT id, username, phone, requester,goodorbad,confirmed,denied FROM request WHERE goodorbad=1 AND confirmed=0 AND denied=0 Order by ID ASC"); 
echo ' 
     <!-- ********************************************************************************************************************************************************** 
     MAIN CONTENT 
     *********************************************************************************************************************************************************** --> 
     <!--main content start--> 
     <section id="main-content"> 
      <section class="wrapper site-min-height"> 
      <h3><i class="fa fa-angle-right"></i> Non Authenticated Requests</h3> 
      <div class="row mt"> 
       <div class="col-lg-12"> 
       <p>Non Authenticated Requests here.</p>'; 
echo '<div class="row mt"> 
        <div class="col-md-12"> 
         <div class="content-panel"> 
          <table class="table table-striped table-advance table-hover"> 
           <h4><i class="fa fa-angle-right"></i>Non Authenticated Requests</h4> 
           <hr> <thead> 
           <tr> 
            <th><i class="fa fa-bullhorn"></i>Username</th> 
            <th><i class="fa fa-phone"></i>Phone number update request</th> 
            <th><i class="fa fa-bookmark"></i>Requester</th> 
            <th><i class=" fa fa-edit"></i> Status</th> 
            <th><i class=" fa fa-edit"></i> Accept/Decline</th> 
            <th></th> 
           </tr> 
           </thead>'; 

$i = 1; 
while($row = $results->fetch_object()) 
{ 

    //$row->id 
    //$row->confirmed 
    //$row->denied 

$status = $row->confirmed; 

echo ' 
    <!-- Modal for Confirm --> 

       <form action="#" method="POST"> 
        <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal'.$i.'" class="modal fade"> 
         <div class="modal-dialog"> 
          <div class="modal-content"> 
           <div class="modal-header"> 
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
            <input type="hidden" name="username_request" value="'.$row->username.'"/> 
             <input type="hidden" name="telephone_request" value="'.$row->phone.'"/> 
            <h4 class="modal-title">Are you sure ?</h4> 
           </div> 
           <div class="modal-body"> 
            <br> 

            <p>You are about to update </p> 
            '.$row->username.' 
            <br> 
            <p> with the following telephone number </p> 
             '.$row->phone.' 

           <div class="modal-footer"> 
            <button data-dismiss="modal" class="btn btn-default" 
              type="button">Cancel</button> 
            <button data-dismiss="modal" class="btn btn-default" 
              type="button">Submit</button> 

           </div> 
          </div> 
         </div> 
        </div> 
        </form> 
        <!-- modal --> 




           <tbody> 
           <tr> 
            <td><a href="#">'.$row->username.'</a></td> 
            <td>'.$row->phone.'</td> 
            <td>'.$row->requester.' </td>'; 
     if($status == 1) 
     { 


       echo '  <td><span class="label label-success">Completed</span></td> 
         <td></td> 
         <td></td> 
         '; 
     } 

          echo '<td><span class="label label-info label-mini">Pending</span></td> 

            <td> 
            Accept? 
            <a data-toggle="modal" href="#myModal'.$i.'"> <button class="btn btn-success btn-xs"><i class="fa fa-check"></i></button> 
            </a> 
            <td> 
            Decline? 
             <button class="btn btn-danger btn-xs"><i class="fa fa-minus-circle"></i></button> 
            </td> 
            </td> 


          </tr> 
           </tbody> 
'; 
$i++; 
} 

echo '  
          </table> 
         </div><!-- /content-panel --> 
        </div><!-- /col-md-12 --> 
       </div><!-- /row -->'; 

// close connection 
$mysqli->close(); 
?> 

<html> 


</html> 
+0

Спасибо, это, кажется, решает мою проблему, но я не понимаю, почему каждая модель нуждается в ID, если вы не возражаете, можете ли вы объяснить мне, почему? – iCeptic

+0

@ user3165482 Структура модели требует уникального 'id', чтобы установить связь между'

+0

@ пользователь3165482 оплатите пожалуйста мой ответ. Если вы сочтете это полезным. – Hassaan

2

Вам придется изменить 2 строки. Причина ошибки заключается в том, что вы вызываете один и тот же идентификатор снова и снова. Таким образом, вам придется динамически менять идентификатор с помощью цикла. Вам придется изменить 2 строки, подобные этим:

<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal'.$i.'" class="modal fade"> 

и

<a data-toggle="modal" href="#myModal'.$i.'"> <button class="btn btn-success btn-xs"><i class="fa fa-check"></i></button></a> 

Окончательный код:

<?php 

require_once ("includes/session_check.php"); 

require_once ("includes/db_connect.php"); 

//MySqli Select Query 
$results = $mysqli->query("SELECT id, username, phone, requester,goodorbad,confirmed,denied FROM request WHERE goodorbad=1 AND confirmed=0 AND denied=0 Order by ID ASC"); 
echo ' 
     <!-- ********************************************************************************************************************************************************** 
     MAIN CONTENT 
     *********************************************************************************************************************************************************** --> 
     <!--main content start--> 
     <section id="main-content"> 
      <section class="wrapper site-min-height"> 
      <h3><i class="fa fa-angle-right"></i> Non Authenticated Requests</h3> 
      <div class="row mt"> 
       <div class="col-lg-12"> 
       <p>Non Authenticated Requests here.</p>'; 
echo '<div class="row mt"> 
        <div class="col-md-12"> 
         <div class="content-panel"> 
          <table class="table table-striped table-advance table-hover"> 
           <h4><i class="fa fa-angle-right"></i>Non Authenticated Requests</h4> 
           <hr> <thead> 
           <tr> 
            <th><i class="fa fa-bullhorn"></i>Username</th> 
            <th><i class="fa fa-phone"></i>Phone number update request</th> 
            <th><i class="fa fa-bookmark"></i>Requester</th> 
            <th><i class=" fa fa-edit"></i> Status</th> 
            <th><i class=" fa fa-edit"></i> Accept/Decline</th> 
            <th></th> 
           </tr> 
           </thead>'; 

$i=0; 
while($row = $results->fetch_object()) { 
$i++; 
    //$row->id 
    //$row->confirmed 
    //$row->denied 

$status = $row->confirmed; 

echo ' 
    <!-- Modal for Confirm --> 

       <form action="#" method="POST"> 
        <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal'.$i.'" class="modal fade"> 
         <div class="modal-dialog"> 
          <div class="modal-content"> 
           <div class="modal-header"> 
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
            <input type="hidden" name="username_request" value="'.$row->username.'"/> 
             <input type="hidden" name="telephone_request" value="'.$row->phone.'"/> 
            <h4 class="modal-title">Are you sure ?</h4> 
           </div> 
           <div class="modal-body"> 
            <br> 

            <p>You are about to update </p> 
            '.$row->username.' 
            <br> 
            <p> with the following telephone number </p> 
             '.$row->phone.' 

           <div class="modal-footer"> 
            <button data-dismiss="modal" class="btn btn-default" 
              type="button">Cancel</button> 
            <button data-dismiss="modal" class="btn btn-default" 
              type="button">Submit</button> 

           </div> 
          </div> 
         </div> 
        </div> 
        </form> 
        <!-- modal --> 




           <tbody> 
           <tr> 
            <td><a href="#">'.$row->username.'</a></td> 
            <td>'.$row->phone.'</td> 
            <td>'.$row->requester.' </td>'; 
     if($status == 1){ 


       echo '  <td><span class="label label-success">Completed</span></td> 
         <td></td> 
         <td></td> 
         '; 
     }else{ 

     } 

          echo '<td><span class="label label-info label-mini">Pending</span></td> 

            <td> 
            Accept? 
            <a data-toggle="modal" href="#myModal'.$i.'"> <button class="btn btn-success btn-xs"><i class="fa fa-check"></i></button> 
            </a> 
            <td> 
            Decline? 
             <button class="btn btn-danger btn-xs"><i class="fa fa-minus-circle"></i></button> 
            </td> 
            </td> 


          </tr> 
           </tbody> 





         '; 
} 

echo '  
          </table> 
         </div><!-- /content-panel --> 
        </div><!-- /col-md-12 --> 
       </div><!-- /row -->'; 

// close connection 
$mysqli->close(); 
?> 

<html> 


</html> 
+0

Я уже разместил ответ/решение 10 месяцев назад и работает для OP. Что нового в вашем ответе? – Hassaan

+2

Наверное, когда вы ответили, я принимал решения. Теперь я вижу, что вы уже дали ответ. Надеюсь, вы понимаете. –

Смежные вопросы