[英]How to display or show all tables in a mysql database into html table with php
我有一個 PHP 腳本,可以在管理員的數據庫(用戶)中創建 3 行的表。
$sql1="CREATE TABLE '".$username."' (id int(5) AUTO_INCREMENT, ip VARCHAR(255), password VARCHAR(255), PRIMARY KEY (id))";
所以我想在管理員的儀表板上顯示用戶數據庫中的所有表(它的行和數據),如下所示:
<h3>Table_Name</h3>
<tr>
<th>Row1</th><th>Row2</th><th>Row3</th>
</tr>
<tr>
<td>All Data On Row1</td><td>All Data On Row2</td><td>All Data On Row3</td>
</tr>
請有人幫助我在這個問題上測試 php mysql 查詢。 我真的不知道如何進行這項工作。 我的 xamp 沒有幫助,因為它似乎無法與數據庫連接,所以我發現很難測試我的代碼; 所以請幫助我編寫經過測試且可運行的代碼。
show TABLES;
DESCRIBE your_table_name;
這是您將數據顯示從數據庫顯示到 HTML 表中的方式
創建數據庫連接
$dbCon= mysqli_connect("localhost","root","root","test"); if(mysqli_connect_errno()){ echo "Failed to connect: ". mysqli_connect_errno(); } ?>
然后在您要以表格形式顯示數據的 php 文件中
<table>
<thead>
<tr>
<th>No.</th>
<th>IP.</th>
<th>Password</th>
</tr>
</thead>
<tbody>
<?php
require("connection.php");
$query="SELECT * FROM your_table_name ";
$result = mysqli_query($dbCon, $query)or die(mysqli_error($dbCon));
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC))
{
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['ip']; ?></td>
<td><?php echo $row['password']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
如果您有更多數據要顯示,只需添加列名。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.