2016-08-15 5 views
0

У меня есть базовый php-скрипт, который подключается к mysql и печатает данные, но у меня проблемы с печатью через html html у меня есть atm, это только часть html только важная часть. К сожалению, я должен набрать много дерьма, так что вы можете увидеть этот код, потому что StackOverflow такой удивительный сайт, это помогает много и много людейmysql print data to display to html

<?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> 
+0

использование ' ....' внутри цикла. – devpro

+0

где цикл я ужасен при кодировании –

ответ

0

Попробуйте это:

<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> 
+0

Вы должны положить это поверх страницы. –

+0

Трудно понять, что перекрывающиеся столбцы. Добавить границу таблицы:

+0

Значение tr должно быть в цикле while. Позвольте мне отредактировать мой ответ –

0

Вы можете распечатать данные внутри HTML, как:

Ваш Хотя блок кода:

<?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 
} 
?> 
+0

Хорошо, наконец, это результат окончания. http://prntscr.com/c61qmx –

+0

@ daz-holmes приятно знать brot – devpro

+0

просто пытается выяснить, как исправить первый ввод данных, он показывает только uid, и последняя запись показывает все, кроме uid, вы знаете, почему? –

0

Завершающий код

<?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>