如何将php变量插入到属性标记的描述中

时间:2017-07-17 19:30:04

标签: php html

您好我正在尝试添加动态删除行列表的功能,并希望使用PHP代码命名html标签的id,您是否有任何想法如何将PHP代码插入到标签属性的描述中(代码在while循环中) it must help me to delete selected rows from list dynamicly),谢谢。

<?php
$connect = mysqli_connect("localhost", "root", "", "guest_book");
$query ="SELECT * FROM users ORDER BY ID DESC";
$result = mysqli_query($connect, $query);
?>
<!DOCTYPE html>
<html>
<head>
    <title>Webslesson Tutorial | Datatables Jquery Plugin with Php MySql and Bootstrap</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
</head>
<body>
<br /><br />
<div class="container">
    <h3 align="center">Datatables Jquery Plugin with Php MySql and Bootstrap</h3>
    <br />
    <div class="table-responsive">
        <table id="employee_data" class="table table-striped table-bordered">
            <thead>
            <tr>
                <td>Id</td>
                <td>Name</td>
                <td>Browser name</td>
                <td>Designation</td>
                <td>Age</td>
                <td>Remove</td>
            </tr>
            </thead>
            <?php
            $id = 1;
            while($row = mysqli_fetch_array($result))
            {
                $but_id = "but"."$id";
                $row_id = 'row'."$id";
                echo ' 
                              <div id = "$row"> // this line <?php ?> dont help

                               <tr>  
                                    <td>'.$row["id"].'</td>  
                                    <td>'.$row["name"].'</td>  
                                    <td>'.$row["browser_name"].'</td>  
                                    <td>'.$row["ip"].'</td>  
                                    <td>'.$row["email"].'</td>  
                                    <td><button type="button" name="remove" id ="$id" class="btn btn-danger btn_remove">X</button></td>// this line 
                               </tr>  
                               </div>

                                                              ';

                ++$id;
            }
            ?>
        </table>
    </div>
</div>
</body>
</html>
<script>
    $(document).ready(function(){
        $('#employee_data').DataTable();
        $('.btn').click(function(){
            var button_id = $(this).attr("id");
            alert(button_id);
            $('#row'+button_id+'').remove();
        });
    });
</script>

1 个答案:

答案 0 :(得分:3)

因为您要将整个字符串放在单引号中,您必须连接该值:

frameworks: ['browserify']

preprocessors: {
      'app/es6/**/*.js':['browserify'],
      'test/unit/es6/**/*.js':['browserify'],
}

browserify: {
      debug: true,
      transform: [["babelify", { "presets": ["es2015"] }]]
    }