|
@@ -14,7 +14,7 @@ function get_field_name($type) {
|
|
|
function get_comments($id, $type) {
|
|
|
global $pdo;
|
|
|
|
|
|
- $sql = 'SELECT * FROM comments WHERE ' . get_field_name($type) . ' = :id';
|
|
|
+ $sql = 'SELECT * FROM comments WHERE ' . get_field_name($type) . ' = :id ORDER BY date DESC';
|
|
|
$values = array(
|
|
|
':id' => $id,
|
|
|
);
|
|
@@ -32,6 +32,27 @@ function get_comments($id, $type) {
|
|
|
return $comments;
|
|
|
}
|
|
|
|
|
|
+function count_comments($id, $type) {
|
|
|
+ global $pdo;
|
|
|
+
|
|
|
+ $sql = 'SELECT count(*) AS count FROM comments WHERE ' . get_field_name($type) . ' = :id';
|
|
|
+ $values = array(
|
|
|
+ ':id' => $id,
|
|
|
+ );
|
|
|
+ try {
|
|
|
+ $res = $pdo->prepare($sql);
|
|
|
+ $res->execute($values);
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ echo 'Query error: ' . $e->getMessage();
|
|
|
+ die();
|
|
|
+ }
|
|
|
+ $comments = [];
|
|
|
+ if($row = $res->fetch(PDO::FETCH_ASSOC)) {
|
|
|
+ return $row['count'];
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
function db_store_comment($nick, $email, $type, $id, $content) {
|
|
|
global $pdo;
|
|
|
|