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条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?