[英]mysql print data to display to html
我有一个基本的php脚本,它可以连接到mysql并打印数据,但是我在通过html进行打印时遇到了问题html我有atm,这只是html的一部分,只是重要部分。 抱歉,我必须输入很多废话,因此您可以看到此代码,因为stackoverflow是一个了不起的网站,它可以帮助很多人
<?php
$servername = "localhost";
$username = "root";
$password = "toor";
$dbname = "a3wasteland";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT UID, BattlEyeGUID, CreationDate, Name, BankMoney FROM PlayerInfo";
$result = $conn->query($sql);
?>
<div class='cWidgetContainer ipsHide' data-controller='core.front.widgets.area' data-role='widgetReceiver' data-orientation='horizontal' data-widgetArea='header'>
<ul class='ipsList_reset'>
</ul>
</div>
<div id="elCmsPageWrap" data-pageid="2">
<div>
<div class='ipsGrid ipsGrid_collapsePhone'>
<div class='ipsGrid_span6'>
<div class='cWidgetContainer ipsHide' data-controller='core.front.widgets.area' data-role='widgetReceiver' data-orientation='horizontal' data-widgetArea='col1'>
<ul class='ipsList_reset'>
</ul>
</div>
</div>
<div class='ipsGrid_span6'>
<div class='cWidgetContainer ipsHide' data-controller='core.front.widgets.area' data-role='widgetReceiver' data-orientation='horizontal' data-widgetArea='col2'>
<ul class='ipsList_reset'>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class='cWidgetContainer ' data-controller='core.front.widgets.area' data-role='widgetReceiver' data-orientation='horizontal' data-widgetArea='footer'>
<ul class='ipsList_reset'>
<li class='ipsWidget ipsWidget_horizontal ipsBox' data-blockID='plugin_20_sodPhpWidget_paxe9xcu5' data-blockConfig="true" data-blockTitle="PHP Code" data-controller='core.front.widgets.block'>
<div class='ipsWidget_inner '>
<p class='ipsType_reset ipsType_medium ipsType_light'>
<style>
.specialType_center th {
text-align: center;
}
</style>
</style>
<h2 class="ipsType_sectionTitle ipsType_reset cForumTitle ipsResponsive_hideTablet ipsResponsive_hidePhone <center> ">Banned Users</h2></center>
<table class="ipsTable ipsTable_responsive ipsTable_zebra ipsBox ipsType_center specialType_center ipsResponsive_hideTablet ipsResponsive_hidePhone">
<thead>
<tr>
<th>UID</th>
<th>BattlEyeGUID</th>
<th>CreationDate</th>
<th>Name</th>
<th>BankMoney</th>
</tr>
</thead>
<tbody>
<tr>
<?php
/* Other code */
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
?>
<td><span class="ipsType_negative"><?=$row["UID"]?></span></td></tr>
<td><span class="ipsType_negative"><?=$row["BattlEyeGUID"]?></span></td>
<td><span class="ipsType_negative"><?=$row["CreationDate"]?></span></td>
<td><span class="ipsType_negative"><?=$row["Name"]?></span></td>
<td><span class="ipsType_negative"><?=$row["BankMoney"]?></span></td>
<?php }
} else { ?>
<td colspan="5">0 results</td>
<?php } ?>
</tr>
</tbody>
</table>
<p class='ipsType_right ipsType_light ipsType_small ipsResponsive_hideTablet ipsResponsive_hidePhone' style='margin-right: 10px;'>Last Update: 15.08.2016, 10:41 </p>
</p>
</div></li>
</ul>
</div>
您可以在html内打印数据,例如:
您的While代码块:
<?php
// use <tr><td></td></tr> inside the loop.
while($row = $result->fetch_assoc()) {
?>
<tr>
<td><span class="ipsType_negative"><?=$row["PlayerUID"]?></span></td>
<td><span class="ipsType_negative"><?=$row["PlayerKills"]?></span></td>
<td><span class="ipsType_negative"><?=$row["AIKILLs"]?></span></td>
<td><span class="ipsType_negative">TeamKills</span></td>
<td><span class="ipsType_negative">DeathCount</span></td>
</tr>
<?php
}
?>
尝试这个:
<thead>
<tr>
<th>PlayerUID</th>
<th>PlayerKills</th>
<th>AIKILLs</th>
<th>TeamKills</th>
<th>DeathCount</th>
</tr>
</thead>
<tbody>
<?php
/* Other code */
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
?>
<tr> <!-- start tr within the loop -->
<td><?php echo $row["PlayerUID"]; ?></td>
<td><?php echo $row["PlayerKills"]; ?></td>
<td><?php echo $row["AIKILLs"]; ?></td>
<td> <!-- Other data --></td>
<td><!-- Other data --></td>
</tr> <!-- end tr within the loop -->
<?php }
} else { ?>
<tr><td colspan="5">0 results</td></tr>
<?php } ?>
</tbody>
整理代码
<?php
$servername = "localhost";
$username = "root";
$password = "toor";
$dbname = "a3wasteland";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT UID, BattlEyeGUID, CreationDate, Name, BankMoney FROM PlayerInfo";
$result = $conn->query($sql);
?>
<div class='cWidgetContainer ipsHide' data-controller='core.front.widgets.area' data-role='widgetReceiver' data-orientation='horizontal' data-widgetArea='header'>
<ul class='ipsList_reset'>
</ul>
</div>
<div id="elCmsPageWrap" data-pageid="2">
<div>
<div class='ipsGrid ipsGrid_collapsePhone'>
<div class='ipsGrid_span6'>
<div class='cWidgetContainer ipsHide' data-controller='core.front.widgets.area' data-role='widgetReceiver' data-orientation='horizontal' data-widgetArea='col1'>
<ul class='ipsList_reset'>
</ul>
</div>
</div>
<div class='ipsGrid_span6'>
<div class='cWidgetContainer ipsHide' data-controller='core.front.widgets.area' data-role='widgetReceiver' data-orientation='horizontal' data-widgetArea='col2'>
<ul class='ipsList_reset'>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class='cWidgetContainer ' data-controller='core.front.widgets.area' data-role='widgetReceiver' data-orientation='horizontal' data-widgetArea='footer'>
<ul class='ipsList_reset'>
<li class='ipsWidget ipsWidget_horizontal ipsBox' data-blockID='plugin_20_sodPhpWidget_paxe9xcu5' data-blockConfig="true" data-blockTitle="PHP Code" data-controller='core.front.widgets.block'>
<div class='ipsWidget_inner '>
<p class='ipsType_reset ipsType_medium ipsType_light'>
<style>
.specialType_center th {
text-align: center;
}
</style>
</style>
<h2 class="ipsType_sectionTitle ipsType_reset cForumTitle ipsResponsive_hideTablet ipsResponsive_hidePhone <center> ">Arma 3 Player Stats</h2></center>
<table class="ipsTable ipsTable_responsive ipsTable_zebra ipsBox ipsType_center specialType_center ipsResponsive_hideTablet ipsResponsive_hidePhone">
<thead>
<tr>
<th>BattlEyeGUID</th>
<th>CreationDate</th>
<th>Name</th>
<th>BankMoney</th>
<th>UID</th>
</tr>
</thead>
<tbody>
<tr>
<?php
/* Other code */
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
?>
<td><span class="ipsType_negative"><?=$row["UID"]?></span></td></tr>
<td><span class="ipsType_negative"><?=$row["BattlEyeGUID"]?></span></td>
<td><span class="ipsType_negative"><?=$row["CreationDate"]?></span></td>
<td><span class="ipsType_negative"><?=$row["Name"]?></span></td>
<td><span class="ipsType_negative"><?=$row["BankMoney"]?></span></td>
<?php }
} else { ?>
<td colspan="5">0 results</td>
<?php } ?>
</tr>
</tbody>
</table>
<p class='ipsType_right ipsType_light ipsType_small ipsResponsive_hideTablet ipsResponsive_hidePhone' style='margin-right: 10px;'>Last Update: 15.08.2016, 10:41 </p>
</p>
</div></li>
</ul>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.