Show sourcecode
The following files exists in this folder. Click to view.
add-article.php
aside.php
blokket-default.php
data/
initiate.php
remove-article.php
show-all-articles.php
show-article.php
update-article.php
update-article_backup.php
show-article.php
1 lines ASCII Unix (LF)
<?php
$path = "incl/blokket/data/";
$db = new PDO("sqlite:incl/blokket2/data/ads");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); // Display errors, but continue script.
$selected = "- Select article -";
if(isset($_POST['article-selection']))
{
$selected = $_POST['article-selection'];
}
?>
<h1>Show article</h1>
<fieldset>
<form method="post">
<p><label for="article-selection">Available articles:</label><br>
<select id="article-selection" name="article-selection" onchange='form.submit();'>
<?php
$stmt = $db->prepare('SELECT * FROM Ads;');
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo "<option value='- Select article -' selected>- Select article -</option>";
foreach ($rows as $row)
{
if ($selected == $row['id'])
echo "<option value='" . $row['id'] . "' selected>" . $row['title'] . "</option>";
else
echo "<option value='" . $row['id'] . "'>" . $row['title'] . "</option>";
}
?>
</select>
</p>
</form>
<?php
if(isset($_POST['article-selection']))
{
if($_POST['article-selection'] != "- Select article -")
{
$stmt = $db->prepare('SELECT * FROM Ads WHERE id=?;');
$id = $_POST['article-selection'];
$stmt->bindParam(1, $id, PDO::PARAM_STR);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$title = $rows[0]['title'];
$image = $rows[0]['image'];
$description = $rows[0]['description'];
echo "<p>" . "<img class='left' src='" . $image . "' width='100'>" . $description . "</p>"; // TODO Move image styling to CSS.
}
}
?>
</fieldset>