about summary refs log tree commit diff stats
path: root/public_html/browser/get.php
blob: fa346c37c226bb73e4c5ff14e6e50163c79b9d1e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

require_once('/home/grizzly/store/browser/db.php');

$member = $_GET['member'];

if (isset($_GET["random"]) || !isset($member)) {
    $stmt = $db->prepare("SELECT * FROM `websites` ORDER BY RANDOM() LIMIT 1;");
    $stmt->execute();
    $row = $stmt->fetch();

    die(header("Location: https://tilde.team/~grizzly/browser/?member=" . $row['login_name']));
} else {
    $stmt = $db->prepare("SELECT * FROM `websites` WHERE login_name = :login_name;");
    $stmt->execute(array(':login_name' => $member));
    $row = $stmt->fetch(); // works

    $stmt = $db->prepare("SELECT login_name FROM `websites` WHERE id > :id;");
    $stmt->execute(array(':id' => $row['id']));
    $next = $stmt->fetch(); // works

    $stmt = $db->prepare("SELECT login_name FROM `websites` WHERE id < :id;");
    $stmt->execute(array(':id' => $row['id']));
    $prev = $stmt->fetch(); // always return first record from database, why?
}

$current = $row["login_name"];
$next = $next["login_name"] ? $next["login_name"] : null;
$prev = $prev["login_name"] ? $prev["login_name"] : null;

// echo "current: " . $current . "\n";
// echo "next: " . $next . "\n";
// echo "prev: " . $prev . "\n";

?>