-
Notifications
You must be signed in to change notification settings - Fork 0
/
lot.php
76 lines (58 loc) · 1.76 KB
/
lot.php
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
$title = 'Лот';
require_once 'init.php';
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$sql = "SELECT *, categories.title as category_title,
GREATEST(COALESCE((select max(amount) from bets where lot_id=lots.id),0), start_amount) as price
FROM lots
JOIN categories on category_id=categories.id
WHERE lots.id=$id";
$result = mysqli_query($link, $sql);
if (!$result){
$error = mysqli_error($link);
show_error($error);
}
if (!mysqli_num_rows($result)) {
http_response_code(404);
show_error('Лот с этим идентификатором не найден');
}
$lot = mysqli_fetch_array($result, MYSQLI_ASSOC);
$user_id = $user['id'];
if($lot['user_id'] == $user_id){
$user['error'] = 'это ваш лот';
}
$sql = "SELECT * FROM bets JOIN users ON user_id=users.id WHERE lot_id=$id ORDER BY reg_date DESC";
$result = mysqli_query($link, $sql);
if (!$result){
$error = mysqli_error($link);
show_error($error);
}
$bets = mysqli_fetch_all($result, MYSQLI_ASSOC);
$user_id = $user['id'];
$sql = "SELECT *
FROM bets
WHERE lots_id=$id AND user_id=$user_id";
$result = mysqli_query($link, $sql);
if (!$result){
$error = mysqli_error($link);
show_error($error);
}
if (mysqli_num_rows($result)) {
$user['error'] = 'ставка уже сделана';
}
$content = include_template('lot.php', [
'categories' => $categories,
'lot' => $lot,
'bets' => $bets,
'user' => $user
]);
$layout = include_template('layout.php', [
'content' => $content,
'categories' => $categories,
'title' => $title,
'user_name' => $user['name'],
'is_auth' => count($user),
'user_avatar' => $user['avatar']
]);
print($layout);
?>