如何在Div被点击后为每个MySQL行制作一个JavaScript警报

How to Make a JavaScript Alert For Each MySQL Row After a Div is Clicked?

本文关键字:警报 JavaScript 一个 MySQL Div      更新时间:2023-09-26

当用户单击id为"showhidestaff"的div时,我想创建一个PHP while循环从表"spc_calendar_calendar "中获取所有MYSQL行' id,然后一个接一个地提醒每个id。到目前为止,使用我在下面发布的代码,JavaScript只警告第一个ID(来自MYSQL表)。下面是我到目前为止的代码:

<script>
    var button22 = document.getElementById('showhidestaff');
    button22.onclick = function() {
if($( "#showhidestaff" ).text() == 'Hide All Calendars') {

    <?php 
    $selectcals = "SELECT * FROM spc_calendar_calendars";
    $results = mysqli_query($dbc, $selectcals);
    while($row = mysqli_fetch_array( $results ))
            {
                $calendar_id = $row['id'];
                $calendar_status = $row['status'];
                    ?>
                    alert("<?php echo $calendar_id;?>");
                    <?php               
            }
    ?> 
    $("#showhidestaff").text('Show All Calendars');     
     }
 </script>

谢谢你的帮助。

现在您将提醒所有id和状态

<script>
        var button22 = document.getElementById('showhidestaff');
        button22.onclick = function() {
    if($( "#showhidestaff" ).text() == 'Hide All Calendars') {

        <?php 
        $selectcals = "SELECT * FROM spc_calendar_calendars";
        $results = mysqli_query($dbc, $selectcals);
        while($row = mysqli_fetch_array( $results ))
                {
                    $calendar_id[] = $row['id'];
                    $calendar_status[] = $row['status'];
                        ?>

                        <?php               
                }
        ?> 
    alert("<?php echo implode(',',$calendar_id);?>");
    alert("<?php echo implode(',',$calendar_status);?>");
        $("#showhidestaff").text('Show All Calendars');     
         }
     </script>