简体   繁体   English

我有一个可点击的行打开一个模态,我希望模式用行的内容填充

[英]I have a clickable row that opens a modal, I would like the modal to be populated with the contents of the row

I have a button where I can create a task, the task details get inserted into my database and then I call that database to display the rows on my page. 我有一个按钮,我可以在其中创建任务,任务详细信息插入到我的数据库中,然后我调用该数据库以显示我的页面上的行。 I currently am able to click on a row but only the details of the last row is shown. 我目前能够点击一行,但只显示最后一行的详细信息。 I ultimately would like to click on a row and then open the modal with all the contents populated. 我最终想点击一行,然后打开所有内容填充的模态。

I have tried the following: 我尝试过以下方法:

-Tried to move php array into a javascript array and then call the array to try and populate my modal depending on what row is clicked. - 尝试将php数组移动到javascript数组中,然后调用数组尝试填充我的模态,具体取决于单击的行。 - Tried to follow this idea Modal Button on each row displays modal which fetch details from database but seems like that would only work if I used a button. - 尝试遵循这个想法每行上的模态按钮显示模式从数据库中获取详细信息,但似乎只有在我使用按钮时才能工作。 -I tried moving the end of the while loop bracket because I thought that the second while loop should be nested in the other but that came with worse results. - 我试图移动while循环括号的结尾,因为我认为第二个while循环应该嵌套在另一个循环括号中,但结果更糟。

  <table class="taskTable" >
 <tbody class="task-tbody">

            <?php while($row1 = mysqli_fetch_array($Table)){ $task123=$row1[2];  ?>
            <tr class = "task-tr"  onclick="document.getElementById('viewTask').style.display='block'">
                <td class="task-td"><input type="checkbox" name="select" value="select"></td>
                <td class="task-td"> <?php if ($row1[0]=='backlog') {$statuscss= 'statusBacklog';} elseif ($row1[0]== 'inprogress') {$statuscss= 'statusInProgress';} else{ $statuscss= 'statusDone';}    echo '<div class="',$statuscss,'">';?><?php echo $row1[0];?></div></td>
                <td class="task-td"> <?php if ($row1[1]=='HIGH') {$statuscss= 'priorityHigh';} elseif ($row1[1]== 'MEDIUM') {$statuscss= 'priorityMedium ';} else{ $statuscss= 'priorityLow';}    echo '<div class="',$statuscss,'">';?>  <?php echo $row1[1];?></div></td>
                <td class="task-td"> <?php echo $task123;?></td>
                <td class="task-description"> <?php echo $row1[3];?></td>
                <td class="task-td"> <?php echo $row1[4];?></td>
                <td class="task-td"> <?php echo $row1[5];?></td>
                <td class="task-td" width="15"> </td>
            </tr>
<?php }?>
    </tbody>
        </table>

        <br><br>

     <div id="viewTask" class="modal" style="display: none;">

        <div class="taskOpenContent">

<?php 

                    $modal123 = "select Tasknumber,Priority,Description,Duedate,Title, Status1 from Universe.Task where Tasknumber=$task123;";

                    $modalqry = mysqli_query($link, $modal123);

                    while ($row = mysqli_fetch_array($modalqry))
                        {
                            $Tasknumber_modal=$row[0];
                            $Priority_modal=$row[1];
                            $Description_modal=$row[2];
                            $Duedate_modal=$row[3];
                            $Title_modal=$row[4];   
                            $status_modal=$row[5];
                        ?>


          <div id="editTask">

            <table class="taskTableOpen">
            <tbody class="task-tbodyOpen">

            <tr class="task-tr">
            <td class="task-td"  id="backlogp">  <?php if ($status_modal=='backlog') {$statuscss= 'statusBacklog';} elseif ($status_modal== 'inprogress') {$statuscss= 'statusInProgress';} else{ $statuscss= 'statusDone';}    echo '<div class="',$statuscss,'">';?><?php echo $status_modal?></td>
            <td class="task-td"><?php if ($Priority_modal=='HIGH') {$statuscss= 'priorityHigh';} elseif ($Priority_modal== 'MEDIUM') {$statuscss= 'priorityMedium ';} else{ $statuscss= 'priorityLow';}    echo '<div class="',$statuscss,'">';?>  <?php echo $Priority_modal;?></div></td>
            <td class="task-td"></td>
            <td class="task-td"><?php echo $Duedate_modal?></td>
            <td class="task-td"><i class="fas fa-user-circle"></i></td>
          </tr>
            </tbody>
            </table>
            <h1 id="title" value="swag"><?php echo $Title_modal?> </h1>

            <p id="content" class="taskDescOpen"></p><?php echo $Description_modal;?></div>

        <button type="button" id="editBtn" class="taskEdit">Edit <i class="far fa-edit"></i></button>
        <p></p>

          <div class="containerComment">
             <textarea placeholder="Comment..." class="taskComment"/></textarea>
          </div>


          <div class="clearfix">
            <button type="reset" onclick="document.getElementById('viewTask').style.display='none'" class="closebtn">Close</button>
          </div>


<?php }?>


        </div>

        </div>

        <script>

    var modal = document.getElementById('viewTask');

$(document).ready(function() {

    $('#table tr').click(function() {
        var href = $(this).find("a").attr("href");
        if(href) {
            window.location = href;
        }
    });

});
</script>

I expected each row to display its own content on click. 我希望每一行都能在点击时显示自己的内容。

One way is to make a modal for each record. 一种方法是为每条记录制作一个模态。 For doing so, put your modal code in the loop and make the id of modal dynamic. 为此,将模态代码放在循环中,并使模态动态的id。 This way is only advisable if number of records are limited. 只有在记录数量有限的情况下才建议采用这种方式。

Refer this : 请参考:

    <table class="taskTable" >
    <tbody class="task-tbody">
            <?php while($row1 = mysqli_fetch_array($Table)){ $task123=$row1[2];  ?>
            <tr class = "task-tr"  onclick="document.getElementById('viewTask<?php echo $task123?>').style.display='block'">
                <td class="task-td"><input type="checkbox" name="select" value="select"></td>
                <td class="task-td"> <?php if ($row1[0]=='backlog') {$statuscss= 'statusBacklog';} elseif ($row1[0]== 'inprogress') {$statuscss= 'statusInProgress';} else{ $statuscss= 'statusDone';}    echo '<div class="',$statuscss,'">';?><?php echo $row1[0];?></div></td>
                <td class="task-td"> <?php if ($row1[1]=='HIGH') {$statuscss= 'priorityHigh';} elseif ($row1[1]== 'MEDIUM') {$statuscss= 'priorityMedium ';} else{ $statuscss= 'priorityLow';}    echo '<div class="',$statuscss,'">';?>  <?php echo $row1[1];?></div></td>
                <td class="task-td"> <?php echo $task123;?></td>
                <td class="task-description"> <?php echo $row1[3];?></td>
                <td class="task-td"> <?php echo $row1[4];?></td>
                <td class="task-td"> <?php echo $row1[5];?></td>
                <td class="task-td" width="15"> </td>
            </tr>
<?php }?>
    </tbody>
        </table>

        <br><br>
     <?php while($row1 = mysqli_fetch_array($Table)){ $task123=$row1[2];  ?>
     <div id="viewTask<?php echo $task123; ?>" class="modal" style="display: none;">
        <div class="taskOpenContent">
            <?php 
                $modal123 = "select Tasknumber,Priority,Description,Duedate,Title, Status1 from Universe.Task where Tasknumber=$task123;";
                $modalqry = mysqli_query($link, $modal123);
                while ($row = mysqli_fetch_array($modalqry))
                {
                    $Tasknumber_modal=$row[0];
                    $Priority_modal=$row[1];
                    $Description_modal=$row[2];
                    $Duedate_modal=$row[3];
                    $Title_modal=$row[4];   
                    $status_modal=$row[5];
                ?>
                <div id="editTask">

                    <table class="taskTableOpen">
                    <tbody class="task-tbodyOpen">
                    <tr class="task-tr">
                    <td class="task-td"  id="backlogp">  <?php if ($status_modal=='backlog') {$statuscss= 'statusBacklog';} elseif ($status_modal== 'inprogress') {$statuscss= 'statusInProgress';} else{ $statuscss= 'statusDone';}    echo '<div class="',$statuscss,'">';?><?php echo $status_modal?></td>
                    <td class="task-td"><?php if ($Priority_modal=='HIGH') {$statuscss= 'priorityHigh';} elseif ($Priority_modal== 'MEDIUM') {$statuscss= 'priorityMedium ';} else{ $statuscss= 'priorityLow';}    echo '<div class="',$statuscss,'">';?>  <?php echo $Priority_modal;?></div></td>
                    <td class="task-td"></td>
                    <td class="task-td"><?php echo $Duedate_modal?></td>
                    <td class="task-td"><i class="fas fa-user-circle"></i></td>
                    </tr>
                    </tbody>
                    </table>
                    <h1 id="title" value="swag"><?php echo $Title_modal?> </h1>
                    <p id="content" class="taskDescOpen"></p><?php echo $Description_modal;?></div>
                    <button type="button" id="editBtn" class="taskEdit">Edit <i class="far fa-edit"></i></button>
                    <p></p>
                    <div class="containerComment">
                        <textarea placeholder="Comment..." class="taskComment"/></textarea>
                    </div>
                    <div class="clearfix">
                        <button type="reset" onclick="document.getElementById('viewTask').style.display='none'" class="closebtn">Close</button>
                    </div>
                    <?php }?>
        </div>
        </div>
        <?php } ?>
        <script>
    var modal = document.getElementById('viewTask');

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

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