-2
I have a table that will list data, but it is A lot of data, which is taking a long time to load the page.
How do I avoid this problem?
Example: That table items will appear according to the scroll bar.
Researching I found this: https://datatables.net/examples/data_sources/server_side , but I didn’t understand how to apply, can anyone help me? here’s the code:
$sql = "SELECT * FROM item_db ORDER BY id ASC";
$sql = $pdo->query($sql);
include "functions/tipo_itens.php";
include "functions/equipa_em.php";
foreach ($sql->fetchAll() as $row) {
$id = $row['id'];
$tipo = $row['type'];
$equipa = $row['equip_locations'];
?>
<tr>
<td><?php echo "<img src='./images/db_itens/icons/$id.png'> ".$row['id'].""; ?></td>
<td><?php echo $row['name_japanese']; ?></td>
<td><?php echo $tipo_itens[$tipo]; ?></td>
<td>
<button type="button" class="btn btn-xs btn-primary" data-toggle="modal" data-target="#mediumModal<?php echo $row['id']; ?>">Visualizar</button>
</td>
</tr>
<!-- Inicio Modal -->
<div class="modal fade" id="mediumModal<?php echo $row['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="mediumModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="mediumModalLabel"><?php echo "<img src='./images/db_itens/images/$id.png'> #".$row['id']." - ".$row['name_japanese'].""; ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p> <b>Nome:</b> <?php echo $row['name_japanese']; ?></p>
<p> <b>Tipo:</b> <?php echo $tipo_itens[$tipo]; ?></p>
<p> <b>Valor de Compra:</b> <?php echo $row['price_buy']; ?></p>
<p> <b>Valor de Venda:</b> <?php echo $row['price_sell']; ?></p>
<p> <b>Peso:</b> <?php echo $row['weight']; ?></p>
<p> <b>Defesa:</b> <?php echo $row['defence']; ?></p>
<p> <b>ATK/MATK:</b> <?php echo "".$row['atk']."/".$row['atk'].""; ?></p>
<p> <b>Nível da Arma:</b> <?php echo $row['weapon_level']; ?></p>
<p> <b>Distância:</b> <?php echo $row['range']; ?></p>
<p> <b>Slots:</b> <?php echo $row['slots']; ?></p>
<p> <b>Nível Mínimo para Equipar:</b> <?php echo $row['equip_level_min']; ?></p>
<p> <b>Equipa em:</b> <?php echo $equipa_em[$equipa]; ?></p>
<p> <b>Script ao usar:</b> <?php echo $row['script']; ?></p>
<p> <b>Script ao equipar:</b> <?php echo $row['equip_script']; ?></p>
<p> <b>Script ao desequipar:</b> <?php echo $row['unequip_script']; ?></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
</div>
</div>
</div>
</div>
<!-- Fim Modal -->
<?php } ?>
i do this by loading only the visible data from the page and using the append with ajax to load more data as the user scrolls down the scroll bar
– Ronaldo Araujo