sql >> Databasteknik >  >> RDS >> Mysql

Hur skickar man nuvarande radvärde i modal?

<?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; 
} 
?>

Placera den här koden någonstans, men på samma sida.

<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>

Skapa ett sidnamn ajax_modal_edit.php (Om du vill ändra detta sidnamn. Ändra i <script></script> tagga också. Båda är relaterade.)

ajax_modal_edit.php

<?php
$teacherid = $_GET['teacherid'];

// Use this `$teacherid` in query to get all 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>

För mer information, kolla Skicka data via Modal Bootstrap och få php-variabel?




  1. Varför \G i SELECT * FROM tabellnamn\G?

  2. ini_set, set_time_limit, (max_execution_time) - fungerar inte

  3. Hur LPAD()-funktionen fungerar i MySQL

  4. Hur man kör en utlösare endast när en specifik kolumn uppdateras (SQL-server)