Php / mysql每行创建一个新表 [英] Php / mysql each row creates a new table

查看:76
本文介绍了Php / mysql每行创建一个新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从MySQL表中读取数据。我希望它显示在一个漂亮的表中的页面上,但是会发生的事情是MySQL表中的每一行都会创建一个新的HTML表。



我一直在玩代码,并在另一个网站上找到了可能的解决方案,但我没有让它工作。它说打开表应该在while部分之前,但是然后我得到HTML表中的第一行,然后是HTML表下的所有行/数据。



这是我现在使用的代码:



data.php



I`m trying to read data from a MySQL table. I want it to show on a page in a nice table, but what happens is that every row from the MySQL table, creates a new HTML table.

I have been playing with the code, and found a "possible" solution on another website, but I don`t get it to work. It says that opening the table should happen before the while part, but then I get the first row in a HTML table, and then all ohter rows/data under the HTML table.

This is the code I use now:

data.php

<?php Header ("Content-type: text/css; charset=utf-8");?>
<link rel="stylesheet" href="style.css">
<?php 
$conn = new mysqli('host', 'user', 'password', 'database');
if ($conn->connect_error) {
	die("Connection error: " . $conn->connect_error);
}

$result = $conn->query("SELECT * FROM table");
if ($result->num_rows > 0) {
	while ($row = $result->fetch_assoc()) {
{
  echo '<table class="table">'; 
  echo "<tr><th>Name</th><th>Description:</th><th>Status</th></tr>";
  echo "<tr><td>"; 
  echo $row['Name'];
  echo "</td><td>";   
  echo $row['Description'];
  echo "</td><td>";    
  echo $row['Status'];
  echo "</td></tr>";
 
}
  echo "</table>";
	}
}
?>





index.php





index.php

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title></title>
	
</head>
<body>
	<div id="show"></div>

	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			setInterval(function () {
				$('#show').load('data.php')
			}, 3000);
		});
	</script>
</body>
</html>





我尝试了什么:



我在谷歌搜索过,发现可能的解决方案似乎不适用于此代码。



What I have tried:

I have searched on Google and found possible solutions that don`t seem to work with this code.

推荐答案

conn = new mysqli('host','user','password','database');
if(
conn = new mysqli('host', 'user', 'password', 'database'); if (


conn-> connect_error){
die(连接错误:。
conn->connect_error) { die("Connection error: " .


conn-> ; connect_error);
}
conn->connect_error); }


这篇关于Php / mysql每行创建一个新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆