Browse Source

Crude "filter" implementation

master
Chimo 5 years ago
parent
commit
4c55f87baa
1 changed files with 32 additions and 3 deletions
  1. +32
    -3
      index.php

+ 32
- 3
index.php View File

@ -6,8 +6,6 @@
</head>
<body>
<?php
require_once('config.php');
@ -22,7 +20,38 @@ try {
die('Connection failed: ' . $e->getMessage());
}
$sql = 'SELECT title, content, published, foreign_url, subscription.type FROM event INNER JOIN subscription ON event.subscription_id = subscription.id ORDER BY published DESC';
$sql = 'SELECT DISTINCT type FROM subscription';
$res = $dbh->query($sql);
$types = array();
$html = '<details><summary>Filters</summary><form>';
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
$types[] = $row['type'];
}
$filters = $_GET['filter'];
$where = '';
foreach($types as $type) {
$html .= '<label><input type="checkbox" name="filter[]" value="' . $type . '" ';
if (!$filters || in_array($type, $filters)) {
$html .= "checked";
$where .= 'OR subscription.type = "' . $type . '"';
}
$html .= ' "> ' . $type . '</label>';
}
$where = ' WHERE ' . substr($where, 2);
$html .= '<input type="submit"></form></details>';
echo $html;
$sql = 'SELECT title, content, published, foreign_url, subscription.type FROM event INNER JOIN subscription ON event.subscription_id = subscription.id' . $where . ' ORDER BY published DESC';
$res = $dbh->query($sql);
$html = '<ol id="list">';


Loading…
Cancel
Save