duangewu5234 2018-08-13 20:05
浏览 58

使用PHP / Jquery在Mysql db中显示值到Html5引导程序

Here's my codes

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();
?>

I am trying to display the data retrieved by the php file using the html table format with bootstrap. I am not sure how to do that. I tried to follow a few guidelines but I couldn't figure out. Any direction towards the right guideline or help would be really appreciated.

Also I am trying to hide the ID from the mysql db and instead show a locally displayed serial number, is it possible to achieve that, if yes how?

Thank you so much.

  • 写回答

1条回答 默认 最新

  • dongma1666 2018-08-13 20:17
    关注

    Step 1 .Put your database connection codes in database_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);
    } 
    

    Step 2. Than include the connection in header of index page

    include("database_connection.php");
    

    Step 3. add these php code inside table tbody And remove the previous codes

    <?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();
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题