douzhan1935 2016-08-15 15:38
浏览 36
已采纳

mysql打印数据显示为html

i've got a basic php script that's connects to mysql and print data but i'm having issues making it print via html the html i have atm this is only part of the html only the important part. Sorry i have to type lots of crap so you can see this code because stackoverflow is such an amazing website, It helps lots and lots of people

<?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>
  • 写回答

3条回答 默认 最新

  • dongquanyu5816 2016-08-15 15:48
    关注

    Try this:

    <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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题