<?php
include_once 'dbconnect.php';
$limit = 15;
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$start = ($page - 1) * $limit;
$result = mysqli_query($link, "SELECT TelegramStorage.id, TelegramStorage.Address, TelegramStorage.Flags, TelegramStorage.Message, TelegramStorage.datum, TelegramStorage.unerledigt,
TelegramDescription.address, TelegramDescription.bezeichnung, TelegramDescription.wache, TelegramDescription.color_n, TelegramDescription.hinweis, TelegramDescription.background_n,
TelegramDescription.gruppe, TelegramDescription.kommune, TelegramDescription.kreis, TelegramDescription.bosmon FROM TelegramStorage
JOIN TelegramDescription WHERE LEFT (TelegramStorage.Address, 7) = LEFT(TelegramDescription.address, 7) AND (TelegramDescription.bosmon = 1) AND (TelegramStorage.Flags = 1048576 OR
TelegramStorage.Flags = 0 OR TelegramStorage.Flags = 1 OR TelegramStorage.Flags = 537919488 OR TelegramStorage.Flags = 536870912) ORDER BY ID DESC LIMIT $start, $limit");
$rows = mysqli_fetch_all($result, MYSQLI_ASSOC);
$count = mysqli_query($link, "SELECT count(id) AS id FROM TelegramStorage JOIN TelegramDescription WHERE LEFT (TelegramStorage.Address, 7) = LEFT(TelegramDescription.address, 7)
AND (TelegramDescription.bosmon = 1) AND (TelegramStorage.Flags = 1048576 OR TelegramStorage.Flags = 0 OR TelegramStorage.Flags = 1 OR TelegramStorage.Flags = 537919488
OR TelegramStorage.Flags = 536870912) ORDER BY ID DESC");
$daten = mysqli_fetch_all($count, MYSQLI_ASSOC);
$total = $daten[0]['id'];
$pages = ceil( $total / $limit );
$next = (int)$page + 1;
if ($next > $pages) { $next = 1; }
?>