使用php/jquery显示mysql数据库到html5引导的值

clj7thdc  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(422)

这是我的密码
html格式

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Control Panel</title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="css/font-awesome.min.css" rel="stylesheet">
    <!-- NProgress -->
    <link href="css/nprogress.css" rel="stylesheet">
    <!-- iCheck -->
    <link href="css/green.css" rel="stylesheet">
    <!-- Datatables -->
    <link href="css/dataTables.bootstrap.min.css" rel="stylesheet">
    <link href="css/buttons.bootstrap.min.css" rel="stylesheet">
    <link href="css/fixedHeader.bootstrap.min.css" rel="stylesheet">
    <link href="css/responsive.bootstrap.min.css" rel="stylesheet">
    <link href="css/scroller.bootstrap.min.css" rel="stylesheet">

    <!-- Custom Theme Style -->
    <link href="css/custom.min.css" rel="stylesheet">
  </head>

  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-12 left_col">
          <div class="left_col scroll-view">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_content">
                    <table id="datatable-buttons" class="table table-striped table-bordered">
                      <thead>
                        <tr>
                          <th>S/N</th>
                          <th>Date</th>
                          <th>IP Address</th>
                          <th>Activation</th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr>
                          <td>get data from db</td>
                          <td>get data from db</td>
                          <td>get data from db</td>
                          <td>get data from db</td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>

    <!-- jQuery -->
    <script src="js/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="js/fastclick.js"></script>
    <!-- NProgress -->
    <script src="js/nprogress.js"></script>
    <!-- iCheck -->
    <script src="js/icheck.min.js"></script>
    <!-- Datatables -->
    <script src="js/jquery.dataTables.min.js"></script>
    <script src="js/dataTables.bootstrap.min.js"></script>
    <script src="js/dataTables.buttons.min.js"></script>
    <script src="js/buttons.bootstrap.min.js"></script>
    <script src="js/buttons.flash.min.js"></script>
    <script src="js/buttons.html5.min.js"></script>
    <script src="js/buttons.print.min.js"></script>
    <script src="js/dataTables.fixedHeader.min.js"></script>
    <script src="js/dataTables.keyTable.min.js"></script>
    <script src="js/dataTables.responsive.min.js"></script>
    <script src="js/responsive.bootstrap.js"></script>
    <script src="js/dataTables.scroller.min.js"></script>
    <script src="js/jszip.min.js"></script>
    <script src="js/pdfmake.min.js"></script>
    <script src="js/vfs_fonts.js"></script>

    <!-- Custom Theme Scripts -->
    <script src="js/custom.min.js"></script>

  </body>
</html>

PHP

<?php
$servername = "remotedbIP";
$username = "root";
$password = "Password";
$dbname = "installation";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT id, date, ip, activate FROM software";
$result = $conn->query($sql);

if ($result->num_rows > 0) {

    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - date: " . $row["date"]. " - ip: " . $row["ip"].  " - activate: " . $row["activate"]. " <br>";
    }
} else {
    echo "0 results";
}
$conn->close();
?>

我正在尝试使用带有引导的html表格式显示php文件检索到的数据。我不知道怎么做。我试着遵循一些准则,但我想不通。我们将非常感谢您的指导和帮助。
另外,我试图从mysql数据库中隐藏id,而不是显示一个本地显示的序列号,是否可以实现这一点,如果可以,如何实现?
非常感谢。

m528fe3b

m528fe3b1#

步骤1.将数据库连接代码放在database\ u connection.php中

$servername = "remotedbIP";
$username = "root";
$password = "Password";
$dbname = "installation";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

第二步。而不是在索引页的标题中包含连接

include("database_connection.php");

第三步。在表tbody中添加这些php代码并删除前面的代码

<?php
$sql = "SELECT id, date, ip, activate FROM software";
$result = $conn->query($sql);

if ($result->num_rows > 0) {

    while($row = $result->fetch_assoc()) {
         echo "<tr>";
         echo "<td> $row['id'] </td>";
         echo "<td> $row['date'] </td>";
         echo "<td> $row['ip'] </td>";
         echo "<td> $row['activate'] </td>";
         echo "</tr>";
    }
} else {
    echo "0 results";
}
$conn->close();
?>

相关问题