Answer the question
In order to leave comments, you need to log in
How to display the result of a sql query in a table on a website?
There are two tables :
With a query
SELECT Client.id, Client.surname, Client.name, Client.patron, Client.serie, Client.number, Client.propiska, Client.telephone, bank.ls, bank.balance, bank.date
FROM bank INNER JOIN Client ON bank.id = Client.id;
<?php
include 'functions.php';
// Connect to MySQL database
$pdo = pdo_connect_mysql();
// Get the page via GET request (URL param: page), if non exists default the page to 1
$page = isset($_GET['page']) && is_numeric($_GET['page']) ? (int)$_GET['page'] : 1;
// Number of records to show on each page
$records_per_page = 5;
// Prepare the SQL statement and get records from our contacts table, LIMIT will determine the page
$stmt = $pdo->prepare('SELECT * FROM Client ORDER BY id LIMIT :current_page, :record_per_page');
$stmt->bindValue(':current_page', ($page-1)*$records_per_page, PDO::PARAM_INT);
$stmt->bindValue(':record_per_page', $records_per_page, PDO::PARAM_INT);
$stmt->execute();
$contacts = $stmt->fetchAll(PDO::FETCH_ASSOC);
$num_contacts = $pdo->query('SELECT Client.id, Client.surname, Client.name, Client.patron, Client.serie, Client.number, Client.propiska, Client.telephone, bank.ls, bank.balance, bank.date
FROM bank INNER JOIN Client ON bank.id = Client.id')->fetchColumn();
?>
<?=template_header('Просмотр')?>
<div class="content read">
<h2>Просмотр контактов</h2>
<a href="create.php" class="create-contact">Создать контакт</a>
<table>
<thead>
<tr>
<td></td>
<td>id</td>
<td>Фамилия</td>
<td>Имя</td>
<td>Отчество</td>
<td>Серия</td>
<td>Номер</td>
<td>Прописка</td>
<td>Телефон</td>
<td></td>
</tr>
</thead>
<tbody>
<?php foreach ($contacts as $contact): ?>
<tr>
<td></td>
<td><?=$contact['id']?></td>
<td><?=$contact['surname']?></td>
<td><?=$contact['name']?></td>
<td><?=$contact['patron']?></td>
<td><?=$contact['serie']?></td>
<td><?=$contact['number']?></td>
<td><?=$contact['propiska']?></td>
<td><?=$contact['telephone']?></td>
<td class="actions">
<a href="update.php?id=<?=$contact['id']?>" class="edit"><i class="fas fa-pen fa-xs"></i></a>
<a href="delete.php?id=<?=$contact['id']?>" class="trash"><i class="fas fa-trash fa-xs"></i></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="pagination">
<?php if ($page > 1): ?>
<a href="read.php?page=<?=$page-1?>"><i class="fas fa-angle-double-left fa-sm"></i></a>
<?php endif; ?>
<?php if ($page*$records_per_page < $num_contacts): ?>
<a href="read.php?page=<?=$page+1?>"><i class="fas fa-angle-double-right fa-sm"></i></a>
<?php endif; ?>
</div>
</div>
<?=template_footer()?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question