php - How to pass current row value in modal? -


i perfoming php crud operations on table. when click edit button rather taking new page want show values in modal. want value's displayed in modal's form. have created modal unable think of logic pass values of row in edit button clicked. highly appreciated.

table:

<table class="table datatable-basic table-bordered table-hover">     <thead>         <tr class='active'>             <th><b>s.no.</b></th>             <th><b>name</b></th>             <th><b>mobile number</b></th>             <th><b>password</b></th>             <th><b>actions</b></th>         </tr>     </thead>      <tbody>         <?php               $sql="select * users order name asc" ;              $c = 1;             $results = $result->query($sql);             while($row = $results->fetch_assoc())              {               echo '<tr style="font-weight:normal;">';               echo "<td>$c</td>";               echo "<td>{$row['name']}</td>";               echo "<td>{$row['username']}</td>";               echo "<td>{$row['pass']}</td>";                echo "<td class='text-center'><ul class='icons-list'><a href='#' style='color:#000;'><i class='icon-pencil5' data-toggle='modal' data-target='#modal_edit'              data-popup='tooltip' title='edit' data-container='body'></i></a>               <a href='delete.php?teacherid={$row['username']}' style='color:#000;'><i class='icon-cross2' data-popup='tooltip' title='delete'               data-container='body'></i></a></ul></td>";               echo '</tr>';                ++$c;              }          ?>     </tbody>     </table>  

my modal this:-

<div id="modal_edit" class="modal fade" style="font-weight: normal;"> <div class="modal-dialog">     <div class="modal-content">         <div class="modal-header">             <button type="button" class="close" data-dismiss="modal">&times;</button>             <h5 class="modal-title">add teacher</h5>         </div>          <form action="" method="post">             <div class="modal-body">                 <div class="form-group">                     <div class="row">                         <div class="col-sm-6">                             <label>full name</label>                             <input type="text" name="fullname" class="form-control" required>                         </div>                          <div class="col-sm-6">                             <label>mobile number</label>                             <input type="text" name="mobno" class="form-control" required>                         </div>                     </div>                 </div>                  <div class="form-group">                     <div class="row">                         <div class="col-sm-6">                             <label>password</label>                             <input type="password" name="password" class="form-control" required>                         </div>                       </div>                 </div>                    <div class="modal-footer">                     <button type="button" class="btn btn-link" data-dismiss="modal">close</button>                     <button type="submit" name="submit" class="btn btn-primary">submit</button>                 </div>             </div>         </form>     </div> </div> 

<?php      .     .     echo "<td class='text-center'>             <ul class='icons-list'>                 <a href='#modal_edit' class='modalbutton' style='color:#000;' data-teacherid='{$row['username']}' data-toggle='modal' data-target='#modal_edit' data-popup='tooltip' title='edit' data-container='body'>                     <i class='icon-pencil5'></i>                 </a>";      echo "<a href='delete.php?teacherid={$row['username']}' style='color:#000;'><i class='icon-cross2' data-popup='tooltip' title='delete'      data-container='body'></i></a></ul></td>";      echo '</tr>';     ++$c;  }  ?> 

place code somewhere, in same page.

<div id="modal_edit" class="modal fade" style="font-weight: normal;">     <div class="modal-dialog">           <div class="modal-content">            </div>     </div> </div> 

js

<script>     $('.modalbutton').click(function(){         var teacherid = $(this).attr('data-teacherid');         $.ajax({url:"ajax_modal_edit.php?teacherid="+teacherid,cache:false,success:function(result){             $(".modal-content").html(result);         }});     }); </script> 

create page name ajax_modal_edit.php (if looking change page name. change in <script></script> tag too. both related.)

ajax_modal_edit.php

<?php $teacherid = $_get['teacherid'];  // use `$teacherid` in query required/appropriate field ?>  <div class="modal-header">     <button type="button" class="close" data-dismiss="modal">&times;</button>     <h5 class="modal-title">add teacher <?php echo $teacherid;?></h5> </div> <form action="" method="post">     <div class="modal-body">         <div class="form-group">             <div class="row">                 <div class="col-sm-6">                     <label>full name</label>                     <input type="text" name="fullname" class="form-control" required>                 </div>                  <div class="col-sm-6">                     <label>mobile number</label>                     <input type="text" name="mobno" class="form-control" required>                 </div>             </div>         </div>         <div class="form-group">             <div class="row">                 <div class="col-sm-6">                     <label>password</label>                     <input type="password" name="password" class="form-control" required>                 </div>             </div>         </div>         <div class="modal-footer">             <button type="button" class="btn btn-link" data-dismiss="modal">close</button>             <button type="submit" name="submit" class="btn btn-primary">submit</button>         </div>     </div> </form> 

for more info, check passing data via modal bootstrap , getting php variable?


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -