Zouden jullie kunnen helpen?
Dit had ik gisteren
Dit heb ik op dit moment.
Ik snap er geen rodebiet meer van helaas.
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
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 = 25;
// Prepare the SQL statement and get records from our contacts table, LIMIT will determine the page
$stmt = $pdo->prepare('SELECT * FROM sgmm 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();
// Fetch the records so we can display them in our template.
$sgmm = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Get the total number of contacts, this is so we can determine whether there should be a next and previous button
$num_sgmm = $pdo->query('SELECT COUNT(*) FROM sgmm')->fetchColumn();
?>
<?=template_header('Read')?>
<div class="content read">
<p>Op dit moment werken we de pagina nummers bij na een nieuwe versie. Deze geeft dus een error aan in de tabellen. We werken er hard aan om dit op te lossen</p>
<h2>Nummers</h2>
<a href="create.php" class="create-contact">Voeg een nummer toe</a>
<table>
<thead>
<tr>
<td>nummer</td>
<td>dienstnummer</td>
<td>vervoerder</td>
<td>bijzonderheden</td>
<td>status</td>
<td>datum laatste signaal</td>
<td>Bijgewerkt op:</td>
<td></td>
</tr>
</thead>
<tbody>
<tr>
<td><?=$sgmm['id']?></td>
<td><?=$sgmm['nummer']?></td>
<td><?=$sgmm['vervoerder']?></td>
<td><?=$sgmm['status']?></td>
<td><?=$sgmm['bijzonderheden']?></td>
<td><?=$sgmm['datum']?></td>
<td><?=$sgmm['editdatum']?></td>
<td class="actions">
<a href="update.php?id=<?=$sgmm['id']?>" class="edit"><i class="fas fa-pen fa-xs"></i></a>
<a href="delete.php?id=<?=$sgmm['id']?>" class="trash"><i class="fas fa-trash fa-xs"></i></a>
</td>
</tr>
</tbody>
</table>
<div class="pagination">
<?php if ($page > 1): ?>
<a href="nummers.php?page=<?=$page-1?>"><i class="fas fa-angle-double-left fa-sm"></i></a>
<?php endif; ?>
<?php if ($page*$records_per_page < $num_sgmm): ?>
<a href="nummers.php?page=<?=$page+1?>"><i class="fas fa-angle-double-right fa-sm"></i></a>
<?php endif; ?>
</div>
</div>
<?=template_footer()?>
<td><?=$sgmm['id']?></td>
<?=$sgmm[0]['id']?>
<?php
$st = $db->prepare(...);
$st->execute();
foreach ($st as $row) {
// doe iets met $row
}
?><?php
// voor ontwikkeling
error_reporting(E_ALL);
ini_set('display_startup_errors', true);
ini_set('display_errors', 'stdout');
// voor debugging
function escape($in) {
return htmlspecialchars($in, ENT_QUOTES, 'UTF-8');
}
function dump($in) {
if (is_array($in)) {
$in = print_r($in, true);
}
echo '<pre>'.escape($in).'</pre>';
}
// voor output
header('Content-Type: text/html; charset=UTF-8');
try {
$db = new pdo('mysql:host=<HOST>;dbname=<DB>;charset=utf8', '<USER>', '<PASSWORD>', array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // maak gebruik van exceptions
PDO::ATTR_EMULATE_PREPARES => false, // gebruik native prepared statements
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, // default fetch modus
));
} catch (Exception $e) {
echo $e->getMessage(); // waarschijnlijk niet verstandig om te dumpen in een productie-omgeving
}
try {
$page = isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1; // is_numeric is mogelijk niet de beste manier om te achterhalen of iets een getal is
$records_per_page = 25;
$st = $db->prepare('SELECT SQL_CALC_FOUND_ROWS * FROM <TABLE> ORDER BY <ID> LIMIT :current_page, :records_per_page');
$st->bindValue(':current_page', ($page - 1) * $records_per_page);
$st->bindValue(':records_per_page', $records_per_page);
$st->execute();
$total = $db->query('SELECT FOUND_ROWS()')->fetchColumn(); // na de execute kun je FOUND_ROWS opvragen
echo 'fetched: '.$st->rowCount().' total: '.$total;
foreach ($st as $row) { // maak gebruik van het feit dat PDOStatement Traversable implementeert
dump($row);
}
} catch (Exception $e) {
echo $e->getMessage();
}
?>[end]