Php 在带有表的网站上显示MySQL数据的最简单方法?
我试图在表中显示数据库中的数据,一列表示名称,另一列表示值,而不是当前的基本布局:Php 在带有表的网站上显示MySQL数据的最简单方法?,php,mysql,Php,Mysql,我试图在表中显示数据库中的数据,一列表示名称,另一列表示值,而不是当前的基本布局: while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) { echo "{$row['date']} <br> ". "--------------------------------<br>". "Temperature :{$row['temperature']} <br> ". "L
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
echo "{$row['date']} <br> ".
"--------------------------------<br>".
"Temperature :{$row['temperature']} <br> ".
"Luminosite : {$row['luminosite']} <br> ".
"Humidite : {$row['humidite']} <br> ".
"--------------------------------<br>";
}
while($row=mysql\u fetch\u数组($retval,mysql\u ASSOC)){
回显“{$row['date']}
”。
“-------------------------------------
”。
“温度:{$row['Temperature']}
”。
“光度:{$row['Luminosite']}
”。
“Humidite:{$row['Humidite']}
”。
“-------------------------------------
”;
}
我对php的所有方面都是新手,所以欢迎提出任何建议。试试这段代码
<table>
<tr>
<td>Date</td><td>Temperature</td><td>Luminosite</td><td>Humidite</td>
</tr>
<?php
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
echo "<tr>
<td>$row['date']</td>
<td>$row['temperature']</td>
<td>$row['luminosite']</td>
<td>$row['humidite']</td>
</tr>";
}
?>
</table>
<html>
<head>
<title>Test</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div>
<div class="row">
<div class="table-responsive">
<table class="table table-striped table-hover" id="my_table">
<thead>
<tr>
<th>Temperature</th>
<th>Luminosite</th>
<th>Humidite</th>
</tr>
</thead>
<tbody>
<?php
$query = "select * from table";
$conn = mysqli_connect("localhost", "root", "password", "ecom");
$data = mysqli_query($conn, $query);
while ($row = mysqli_fetch_array($data))
{
$temperature = $row['temperature'];
$luminosite = $row['luminosite'];
$humidite = $row['humidite'];
echo "<tr><td>$temperature</td><td>$luminosite</td><td>$humidite</td></tr>";
}
; ?>
</tbody>
</table>
</div>
</div>
</div>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
DateTemperatureLuminosite腐殖岩
尝试使用下面的代码
echo "<table>
<tr>
<th>Date</th>
<th>Name</th>
<th>luminosite</th>
<th>humidite</th>
</tr>";
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
echo "<tr>
<td>".$row['date']."</td>
<td>".$row['temperature']."</td>
<td>".$row['luminosite']."</td>
<td>".$row['humidite']."</td>
</tr>";
}
echo "</table>";
echo”
日期
名称
光度
腐殖石
";
而($row=mysql\u fetch\u数组($retval,mysql\u ASSOC)){
回声“
“$row['date']”
“$row[‘温度’]”
“$row['luminosite']”
“$row['humidite']”
";
}
回声“;
不要使用MySQL
<table>
<tr>
<?php
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
?>
<td>
<?php echo "{$row['date']};?>
<td>
<td>
<?php echo "{$row['temperature']};?>
<td>
<!-- other fiels -->
<?php
}
?>
</tr>
</table>
尝试使用此代码
<table>
<tr>
<td>Date</td><td>Temperature</td><td>Luminosite</td><td>Humidite</td>
</tr>
<?php
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
echo "<tr>
<td>$row['date']</td>
<td>$row['temperature']</td>
<td>$row['luminosite']</td>
<td>$row['humidite']</td>
</tr>";
}
?>
</table>
<html>
<head>
<title>Test</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div>
<div class="row">
<div class="table-responsive">
<table class="table table-striped table-hover" id="my_table">
<thead>
<tr>
<th>Temperature</th>
<th>Luminosite</th>
<th>Humidite</th>
</tr>
</thead>
<tbody>
<?php
$query = "select * from table";
$conn = mysqli_connect("localhost", "root", "password", "ecom");
$data = mysqli_query($conn, $query);
while ($row = mysqli_fetch_array($data))
{
$temperature = $row['temperature'];
$luminosite = $row['luminosite'];
$humidite = $row['humidite'];
echo "<tr><td>$temperature</td><td>$luminosite</td><td>$humidite</td></tr>";
}
; ?>
</tbody>
</table>
</div>
</div>
</div>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
试验
温度
光度
腐殖石
阅读基本的PHP和MySQL教程。如果你每次遇到一个小小的绊脚石,就让问答网站上的人帮你写代码,你永远也不会学会如何为自己编写代码。另外,作为一个指针:不要使用以mysql\uuu
开头的函数-它们已被弃用:正是我所需要的。我现在只需要在两个单元格之间添加线条。对不起,文森特,请你详细解释一下你到底需要什么。有屏幕截图或输出结构吗?