Website/ajax/artikel.php
2020-11-25 16:59:57 +01:00

46 lines
1.2 KiB
PHP

<?php #ajax/get.php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once "../conf.php";
$article = $_POST["article"] ?? "Empty";
$sections = array();
if ($stmt = $mysqli->prepare("select name from sections s where article = ? order by ord asc")) {
$stmt->bind_param("s", $article);
$stmt->execute();
$stmt->bind_result($name);
while ($stmt->fetch()) {
$sections[] = $name;
}
}
$name = isset($_POST["section"]) && $_POST["section"]!="" ? $_POST["section"] : ($sections[0] ?? "Empty");
$content = "Hallo";
if ($stmt = $mysqli->prepare("select content from sections s where name = ? and article = ?")) {
$stmt->bind_param("ss", $name, $article);
$stmt->execute();
$stmt->bind_result($content);
$stmt->fetch();
}
$id = preg_replace('/\s+/', '', $article."_".$name);
?>
<footer>
<h1><?=$article;?></h1>
<?php if (count($sections)>1) { ?>
<ul>
<?php foreach ($sections as $sec) { ?>
<a href='javascript:loadArticle("<?=basename(__FILE__);?>", "<?=$article;?>", "<?=$sec;?>")'<?=($sec==$name ? " class='current'" : "");?>><li><?=$sec;?></li></a>
<?php } ?>
</ul>
<?php } ?>
</footer>
<section id='<?=$id;?>'><?=$content;?></section>