Výpis dle kriterií z DATABAZE_FIREM_2023

set_charset("utf8mb4"); } catch (mysqli_sql_exception $e) { error_log("vypisf.php: " . $e->getMessage()); exit("

Databáze je momentálně nedostupná.

"); } // LIKE vzor s escapovanými zástupnými znaky (% a _ hledá doslova) $like = fn(string $s): string => '%' . addcslashes($s, '%_\\') . '%'; // WHERE skládej jen z vyplněných polí (prázdné město nevyřadí řádky s mesto = NULL) $where = []; $types = ''; $args = []; if ($parametr !== '') { $where[] = "(Obor LIKE ? OR popis LIKE ?)"; $types .= 'ss'; array_push($args, $like($parametr), $like($parametr)); } if ($mesto !== '') { $where[] = "mesto LIKE ?"; $types .= 's'; $args[] = $like($mesto); } $whereSql = implode(' AND ', $where); try { // COUNT $stmtC = $mysql_id->prepare("SELECT COUNT(*) AS cnt FROM DATABAZE_FIREM_2023 WHERE $whereSql"); $stmtC->bind_param($types, ...$args); $stmtC->execute(); $total = (int)($stmtC->get_result()->fetch_assoc()['cnt'] ?? 0); $stmtC->close(); $totalPages = max(1, (int)ceil($total / $perPage)); if ($page > $totalPages) { $page = $totalPages; $offset = ($page - 1) * $perPage; } // DATA $sqlData = "SELECT telefon, nazev, Obor, email, web, mesto, ulice, psc, popis FROM DATABAZE_FIREM_2023 WHERE $whereSql ORDER BY mesto, ulice ASC LIMIT ? OFFSET ?"; $stmt = $mysql_id->prepare($sqlData); $stmt->bind_param($types . 'ii', ...[...$args, $perPage, $offset]); $stmt->execute(); $result = $stmt->get_result(); } catch (mysqli_sql_exception $e) { error_log("vypisf.php: " . $e->getMessage()); exit("

Při dotazu do databáze došlo k chybě.

"); } echo "
Nalezeno: ".h($total)." · Strana ".h($page)." / ".h($totalPages)."
"; // Pager link builder (zachová filtr) $baseParams = [ 'parametr' => $parametr, 'mesto' => $mesto, ]; $makeLink = function(int $p, string $label, string $class="") use ($baseParams) { $params = $baseParams + ['p' => $p]; $url = h($_SERVER['PHP_SELF']).'?'.http_build_query($params, '', '&'); $cls = $class ? " class='".h($class)."'" : ""; return "".h($label).""; }; $window = 3; $start = max(1, $page - $window); $end = min($totalPages, $page + $window); echo "
"; echo ($page > 1) ? $makeLink($page-1, "« Předchozí") : "« Předchozí"; if ($start > 1) { echo $makeLink(1, "1"); if ($start > 2) echo "…"; } for ($p = $start; $p <= $end; $p++) { if ($p === $page) echo "".h($p).""; else echo $makeLink($p, (string)$p); } if ($end < $totalPages) { if ($end < $totalPages - 1) echo "…"; echo $makeLink($totalPages, (string)$totalPages); } echo ($page < $totalPages) ? $makeLink($page+1, "Další »") : "Další »"; echo "
"; // Výpis echo "
"; echo ""; $i = $offset; while ($fetch = $result->fetch_assoc()) { ++$i; $webRaw = trim((string)($fetch['web'] ?? '')); $web = ''; if ($webRaw !== '') $web = preg_match('~^https?://~i', $webRaw) ? $webRaw : 'https://'.$webRaw; $tel = trim((string)($fetch['telefon'] ?? '')); $email = trim((string)($fetch['email'] ?? '')); // tel: jen číslice a +, 00420… → +420…, chybějící předvolba → +420 $telHref = ''; if ($tel !== '') { $digits = preg_replace('/^00/', '+', preg_replace('/[^\d+]/', '', $tel)); $telHref = str_starts_with($digits, '+') ? $digits : ((strlen($digits) === 12 && str_starts_with($digits, '420')) ? '+'.$digits : '+420'.$digits); } echo ""; echo ""; echo $tel !== "" ? "" : ""; echo ""; echo ""; echo $email !== "" ? "" : ""; echo $web !== "" ? "" : ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
# Telefon Název Obor E-mail Web Město Ulice PSČ Popis
".h($i)."☎ ".h($tel)."—".h($fetch['nazev'] ?? '')."".h($fetch['Obor'] ?? '')."".h($email)."—".h($web)."—".h($fetch['mesto'] ?? '')."".h($fetch['ulice'] ?? '')."".h($fetch['psc'] ?? '')."".h($fetch['popis'] ?? '')."
"; $stmt->close(); $mysql_id->close(); } ?>