ADD: database utility toolbar added to image page, search worx, order does not yet

This commit is contained in:
TheShinyMelon 2024-11-16 22:00:15 +01:00
parent aa0dd82856
commit ba6eefbbab
4 changed files with 50 additions and 5 deletions

View File

@ -8,9 +8,10 @@
echo $e->getMessage(); echo $e->getMessage();
} }
function get_images($pdo) { function get_images($pdo, $search='%', $sort='img_date', $sdir='DESC') {
$stmt = $pdo->prepare("SELECT * FROM images;"); $params = array('search' => $search, 'sort' => $sort, 'sdir' => $sdir);
$stmt->execute(); $stmt = $pdo->prepare("SELECT * FROM images WHERE img_title LIKE CONCAT('%', :search ,'%') ORDER BY :sort :sdir;");
$stmt->execute($params);
$data = $stmt->fetchAll(); $data = $stmt->fetchAll();
$img_list = '<ul class="img_list">'; $img_list = '<ul class="img_list">';

View File

@ -1,7 +1,46 @@
<h1 class='cat_heading'>> chosen file type: image<br>&nbsp;&nbsp;listing files...</h1> <h1 class='cat_heading'>> chosen file type: image<br>&nbsp;&nbsp;listing files...</h1>
<form class='db_utilities' method='POST'>
<label for='sel_order'>order by</label>
<select name='sel_order' id='sel_order'>
<option value='new'>newest</option>
<option value='old'>oldest</option>
<option value='az'>A - Z</option>
<option value='za'>Z -A</option>
</select>
<label for='inp_search'>search</label>
<input type='search' name='inp_search' id='inp_search'></input>
<input type='submit' value='filter'></input>
</form>
<?php <?php
include_once('../app/db_connector.php'); include_once('../app/db_connector.php');
get_images($pdo);
if( isset($_POST['sel_order']) && isset($_POST['inp_search']) ) {
$sort = 'date';
$sdir = 'DESC';
var_dump($sort, $sdir);
switch($_POST['sel_order']) {
case 'new':
break;
case 'old':
$sdir = 'ASC';
break;
case 'az':
$sort = 'img_name';
$sdir = 'ASC';
break;
case 'za':
$sort = 'img_name';
break;
default:
break;
}
get_images($pdo, $_POST['inp_search'], $sort, $sdir);
}
else {
get_images($pdo);
}
?> ?>

View File

@ -67,6 +67,7 @@
<p class='footer_element'> <p class='footer_element'>
<a href='./index.php?el=legal'>legal information</a> <a href='./index.php?el=legal'>legal information</a>
<a href='./index.php?el=privacy'>privacy policy</a> <a href='./index.php?el=privacy'>privacy policy</a>
<a href='./index.php?el=contact'>contact</a>
</p> </p>
<p class='footer_element'><a href='https://layer-8.moe/'>layer-8.moe</a> is a non-commercial homepage created by a private individual in 2024</p> <p class='footer_element'><a href='https://layer-8.moe/'>layer-8.moe</a> is a non-commercial homepage created by a private individual in 2024</p>
<p class='footer_element'> <p class='footer_element'>

View File

@ -138,3 +138,7 @@ footer {
padding: 1rem; padding: 1rem;
padding-left: 5rem; padding-left: 5rem;
} }
.db_utilities {
padding: 2rem;
}